Tutorial MySQL: How to Group By Two or More Column in MySQL!
So you trying to group data by multiple column here and you're using MySQL? There is no native way to do that, you have to combine 'Group By' syntax with other else.
Regular Group by would be like this:
[sourcecode language="sql"]
select client_id, name, max(cash + stocks)
from client join portfolio using (client_id)
group by client_id
+-----------+----------+--------------------+
| client_id | name | max(cash + stocks) |
+-----------+----------+--------------------+
| 1 | John Doe | 33.33 |
| 2 | Jane Doe | 90.90 |
+-----------+----------+--------------------+
[/sourcecode]
to group by two column, you need to concat those two column first, your syntax will be like this:
[sourcecode language="sql"]
select client_id, name, max(cash + stocks)
from client join portfolio using (client_id)
group by concat(client_id,name)
[/sourcecode]
Understand now?
God bless your SQL...