Link to home
Start Free TrialLog in
Avatar of Xbradders
Xbradders

asked on

SQL Query to select an ID IF it exists in another table

Hello, I've inherited some bad data and am trying to work with it, and I need help getting creative with a query.

I have a simple table called Songs.  I want to select the song name and tempo for all songs on a given album.  Unfortunately the song tempo is not store in the Songs table.  It is off in some table that stores various sub categories.  

There is a lookup table called Songs_SubCategories, that has two fields: SongID, SubCategoryID.  SongID joins to Songs.SongID.  Each Song will have one record in Songs_SubCategories with the SongID and SubCategoryID of: 135,136,137,138, or 139.  The values correspond to a Tempo in another table.  

This would be simple, but there are other Song SubCategory IDs stored in Songs_SubCategories, so I can't just join by SongID.  I need to select by SongID, where SubCategoryID in 135-139.

How would I write the query to get the SongName and the corresponding SubCategoryID as 'SongTempoID'?  I essentially want:
SELECT SongID, SongName, SongTempoID FROM Songs where albumId = 10;  Where SongTempoID is either 135,136,137,138, or 139.

I hope I'm making sense here.  Thanks -
SOLUTION
Avatar of David Todd
David Todd
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial