/*sqlserver*/ select Id,AId,(SELECT IMEI+',' FROM Device as s WHERE s.Id=c.Id For XML Path('')) AS IMEI from Device as c /*mysql*/ select AId,(SELECT group_concat(IMEI) FROM Device as s WHERE s.AId=c.AId ) AS IMEI from AccountSettings as c