Home  >  Article  >  Backend Development  >  How to get the latest value from multiple IDs in a joint query in mysql?

How to get the latest value from multiple IDs in a joint query in mysql?

WBOY
WBOYOriginal
2016-08-04 09:19:071024browse

For example, take a record of the user’s highest score

user table

id name
1 aaa
2 bbb
3 ccc

Score table

uid score
1 10
1 32
1 88
2 21
2 4
3 93
3 70

user.id = s.uid

How to get the user’s highest score record using a joint table

Thank you in advance

Reply content:

For example, get a record of the user’s highest score

user table

id name
1 aaa
2 bbb
3 ccc

Score table

uid score
1 10
1 32
1 88
2 21
2 4
3 93
3 70

user.id = s.uid

How to get the user’s highest score record using a joint table

Thank you in advance

select user.name, user.id, max(s.score) from s inner join user.id = s.uid group by s.uid

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn