Skip to content

emka.web.id

Menu
  • Home
  • Indeks Artikel
  • Tutorial
  • Tentang Kami
Menu

Tutorial MySQL: How to Group By Two or More Column in MySQL!

Posted on November 02, 2016 by Syauqi Wiryahasana
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...
Seedbacklink

Recent Posts

TENTANG EMKA.WEB>ID

EMKA.WEB.ID adalah blog seputar teknologi informasi, edukasi dan ke-NU-an yang hadir sejak tahun 2011. Kontak: kontak@emka.web.id.

©2024 emka.web.id Proudly powered by wpStatically