Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL Join many to many

I have three tables:

producer:
Producer

series_producer:
series_producer

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and series:
series

What i am trying to do is to do a select on producers and also show the names of the series they have created.
ex.

producer_id    producer_name    producer_series
1              Marta Kauffman   Friends, Dream On

I am able to show it with the id of the series, but i want the name instead..

This is my SQL to do that:

-- View all series from one producer
select producer_id, producer_name, group_concat(series_producer_sid) as prods
from producer w join
     series_producer uw
     on producer_id = uw.series_producer_pid
group by producer_id;

How can i do it?

Thanks in advance!

>Solution :

Try this:

select 
  producer_id, 
  producer_name, 
  group_concat(s.series_name) as prods
from producer as w 
join series_producer as uw
  on w.producer_id = uw.series_producer_pid
join series as s
  on uw.series_producer_sid = s.series_id
group by producer_id;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading