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

 

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.