Jump to content

Need help with simple sql SELECT w/JOIN statement.


techdude

Recommended Posts

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.