ultrus Posted February 28, 2012 Share Posted February 28, 2012 Hi, I have contact info stored in two tables. Each person in the people table has multiple pieces of contact info (phone number, email, etc.) in the info table. I can left join for multiple rows of fun (with repeating person details) like this: SELECT p.first_name, p.last_name, i.info_type, i.info_content FROM people p LEFT JOIN info i ON i.person_id = p.id resulting in something like this: Bobola, Fossmosto, E, [email protected] Bobola, Fossmosto, P, +1.111.111.1111 How would I alter my query to get something like this? first_name, last_name, c1_type, c1_content, c2_type, c2_content Bobola, Fossmosto, E, [email protected], P, +1.111.111.1111 Thanks for pointers in advance. Link to comment https://forums.phpfreaks.com/topic/257921-combining-multiple-rows-into-single-row-output-for-spreadsheet/ Share on other sites More sharing options...
ultrus Posted February 28, 2012 Author Share Posted February 28, 2012 I got it. Never mind. It's something like: SELECT p.first_name, p.last_name, (SELECT i.info_type FROM info i WHERE i.person_id = p.id ORDER BY i.sortby ASC LIMIT 0,1) AS c1_type, (SELECT i.info_type FROM info i WHERE i.person_id = p.id ORDER BY i.sortby ASC LIMIT 1,1) AS c2_type, FROM people p Link to comment https://forums.phpfreaks.com/topic/257921-combining-multiple-rows-into-single-row-output-for-spreadsheet/#findComment-1322005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.