mysql select distinct column based on group by column -


hi have following columns

| id | name | category| |  1 | sam  | doctor  | |  2 | tom  | doctor  | |  3 | pam  | nurse   | |  4 | gum  | nurse   | |  5 | tom  | doctor  | |  6 | lim  | doctor  | 

i want run query choose distinct names based on category namecolumn unique below

| id | name | category| |  1 | sam  | doctor  | |  2 | tom  | doctor  | |  3 | pam  | nurse   | |  4 | gum  | nurse   | |  6 | lim  | nurse   | 

it baffles me

you use min:

select min(id), name, category yourtable group name, category 

if want distinct names, since you're using mysql, work (but return random ids , categories). if need specific ids/categories, you'll need define them in aggregate (as in previous solution):

select id, name, category yourtable group name 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -