MySQL INNER JOIN select only one row from second table

后端 未结 11 1013
不知归路
不知归路 2020-11-30 21:11

I have a users table and a payments table, for each user, those of which have payments, may have multiple associated payments in the payments

11条回答
  •  情书的邮戳
    2020-11-30 21:31

    This is quite simple do The inner join and then group by user_id and use max aggregate function in payment_id assuming your table being user and payment query can be

    select user.id, max(payment.id) from user inner join payment on (user.id = payment.user_id) group by user.id

提交回复
热议问题