Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select max similar rows by numeric field for all users

Tags:

select

mysql

we have table as below :

  user    point
+-------+------+  
| user1 | 6080 | // user1 has this value  
+-------+------+  
| user1 | 5300 |  
+-------+------+  
| user2 | 6080 | // user2 has this value  
+-------+------+  
| user3 | 6080 | // user3 has this value  
+-------+------+  
| user3 | 5300 |  
+-------+------+  
| user1 | 3520 |  
+-------+------+  
| user2 | 5300 |  
+-------+------+  
| user3 | 9800 |  

i want to get the max similar value that all users have at least one of that in this sample there are two value that all users have. 6080 and 5300

result should be 6080

how can i do that ?

like image 686
Omid Avatar asked Jan 30 '26 05:01

Omid


1 Answers

Would look like this. You need to limit the results to 1, so for example for mysql you should use limit 1 at the end or for mssql select top 1 point .. etc etc.

select point
from user
group by point
having count(*)=(select count(distinct user) from user)
order by point desc
like image 164
Dumitrescu Bogdan Avatar answered Jan 31 '26 19:01

Dumitrescu Bogdan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!