[Solved] MySQL Select from three tables [closed]


something like this?

QUERY:

SELECT country, profession, MAX(money) AS money 
FROM
(   SELECT u.country, g.profession, SUM(um.money) AS money
    FROM user_money um
    JOIN users u ON u.id = um.user_id
    JOIN groups g ON g.id = um.group_id
    GROUP BY g.profession, u.country
    ORDER BY um.money DESC
) t
GROUP BY country
ORDER BY money DESC

SEE DEMO

OUTPUT:

+---------------+------------+-------+
| country       | profession | money |
+---------------+------------+-------+
| Luxembourg    | Hacker     |  200  |
| Albania       | Hacker     |  120  |
| United States | Boss       |  55   |
+---------------+------------+-------+

5

solved MySQL Select from three tables [closed]