Q: count records and join tables I have tow tables that i want to join below are the details of the tables
Trophy_lookup table contains
id | user_id | trophy_id
1  | 2       | 2
2  | 3       | 4
3  | 1       | 5
4  | 2       | 1
4  | 1       | 1

Users table contains general user information
id | name    | email
1  | john    | john@webcom
2  | jacky   | jacky@web.com
3  | Smith   | smith@web.com
4  | Rob     | rob@web.com

Problem
I want to join users and trophy_lookup table in a way that i can count how many trophis a user win along with user name Below is my desired output that i want to achieve.
user_id| name | count(trophis)
     1 | john | 2
     2 | jacky| 2

So far i have tried many things but i am unable to achieve above results. I am not very good with writing queries, so Please guide me with this. Thanks

A: Try this query 
select a.id, a.name, count(*) as cnt
from table2 a 
inner join 
table1 b
on a.id = b.user_id
group by 
a.id, a.name
having count(*) > 1
order by cnt

SQL FIDDLE:
| ID |  NAME | CNT |
--------------------
|  2 | jacky |   2 |
|  1 |  john |   2 |

Alternate approach
select a.name, b.* 
from table2 a
inner join 
(select a.id, count(*) as cnt
from table2 a 
inner join 
table1 b
on a.id = b.user_id
group by 
a.id) b 
ON a.id=b.id
where cnt > 1

SQL FIDDLE:
|  NAME | ID | CNT |
--------------------
|  john |  1 |   2 |
| jacky |  2 |   2 |


A: Try this query:
SELECT u.id,count(u.id),u.name 
FROM trophy_lookup t 
JOIN users u ON t.user_id=u.id 
GROUP BY u.id ;

