techdude Posted May 13, 2011 Share Posted May 13, 2011 Hi folks! I need some help coming up with the correct query to perform this. I have several tables, but to simplify it, we will just put it like this: TABLES: employees languages employee_languages (used to link multi to multi) I need to select * from employees with all the languages they speak. I am not quite sure how to do this, but I expect the result to be something like: +-----------------+-----------------------+-----------------------+ | employee_id | employee_name | languages | +-----------------+-----------------------+-----------------------+ | 1 | Joe Smith | English, Spanish | +-----------------+-----------------------+-----------------------+ I know there is a simple solution, but I just can't seem to find it. Thanks for any help! -- techdude Link to comment https://forums.phpfreaks.com/topic/236346-need-help-with-simple-sql-select-wjoin-statement/ Share on other sites More sharing options...
techdude Posted May 13, 2011 Author Share Posted May 13, 2011 ARRRGH! Why is it that I always procrastinate posting to this forum, and then the minute I post, I figure out my problem? Any way, the solution is as follows: SELECT e.employee_id, e.employee_name, GROUP_CONCAT(l.language SEPARATOR ", ") as languages, FROM employees e JOIN (employee_languages `el`, languages l) ON (e.employee_id = `el`.employee_id AND `el`.language_id = i.language_id); Oh well, Problem solved. hope this post helps someone else. -- techdude Link to comment https://forums.phpfreaks.com/topic/236346-need-help-with-simple-sql-select-wjoin-statement/#findComment-1215176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.