sql - How do you select only the first row and specific column of multiple rows with the same value? -


let's have query result looks follows:

id    name    phone ----  ----    ----- 1     john    123456 2     john    125678 3     john    345678 4     abby    456789 5     abby    567890 

i want return single row instance of name: john, phone number '12%'.

mysql has nifty aggregate function group_concat() can list telephone numbers (separated comma) person doing like

select name, group_concat(phone) numbers tbl group name 

this

name    numbers  ----    -------------------- abby    456789,567890 john    123456,125678,345678 

with condition name='john' , phone '12%' get

select name, group_concat(phone) numbers tbl  name='john' , phone '12%' group name 

you fewer results like

name    numbers ----    ------------- john    123456,125678 

Comments