Mysql
 sql >> Database >  >> RDS >> Mysql

INTERNO o SINISTRO Unire più record di tabelle in una singola riga

Sebbene tu possa unire più numeri (in qualsiasi) in un unico campo:

SELECT
  CONCAT(f_first_name, ' ', f_last_name) as Client_Name,
  GROUP_CONCAT(IF(phone_type='work',f_phone_number, NULL)) as Work_Numbers,
  GROUP_CONCAT(IF(phone_type='home',f_phone_number, NULL)) as Home_Numbers
FROM clients
JOIN phone
  USING (f_id)
WHERE phone_type IN ('home', 'work')
GROUP BY f_id;