Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query join help needed

Author  Topic 

jnmunsey
Starting Member

4 Posts

Posted - 2006-04-13 : 02:41:26
I have one table with(many to many relationship):
performerid
performername
eventid

another table with:
eventid
eventname

I want to make a query that lists all eventnames for a given performerid

Any help is appreciated

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-13 : 02:43:40
use INNER JOIN
select e.eventid, e.eventname, p.performerid, p.performername
from event e inner join perform p
on e.eventid = p.eventid




KH


Go to Top of Page

jnmunsey
Starting Member

4 Posts

Posted - 2006-04-13 : 02:54:18
Never mind I figured it out on the first try...

SELECT Events.* FROM EventPerformers LEFT JOIN Events ON EventPerformers.EventID=Events.EventID WHERE EventPerformers.EventID = Events.EventID AND EventPerformers.PerformerID = 61

61 is a performerid

oh and this was for MySQL
Go to Top of Page

jnmunsey
Starting Member

4 Posts

Posted - 2006-04-13 : 02:56:12
thanks khtan.. Is there any performance issue with my solution? It seems to work just fine.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-13 : 03:01:45
quote:
Originally posted by jnmunsey

thanks khtan.. Is there any performance issue with my solution? It seems to work just fine.


as long as you have index for the eventid and performerid

quote:
oh and this was for MySQL

Oh ! this is a MS SQL Server forum



KH


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-13 : 03:36:56
>>oh and this was for MySQL

Post your MySQL questions at www.DBForums.com or www.MySQL.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jnmunsey
Starting Member

4 Posts

Posted - 2006-04-13 : 03:41:02
Thanks, but with a response as fast a this, I might just come back here (it was a generic SQL question after all). Plus, I might be able to help someone some day.
Go to Top of Page
   

- Advertisement -