MySQL subqueries

rlwebb

New Member
Joined
May 12, 2006
Messages
6
I am trying to use a subquery to pull out the names of the four members of the band coldplay, which is grp_id 1 in table joins. I can get the artist ID from joins, but then I need the artist table to link over to the member's name. Anyone tell me what's wrong with my query? Thanks.

Code:
mysql> SELECT art_name FROM artist WHERE art_id IN (SELECT art_id FROM joins WHERE
 grp_id=1);
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I don't see anything wrong with your SQL, are you getting an error when you run it?

You don't need a sub-query for this, this should work fine:
Code:
SELECT 
a.art_name 
FROM 
artist a
, joins j
WHERE a.art_id = j.art_id
AND j.grp_id=1;

hth,
Giacomo
 
Upvote 0

Forum statistics

Threads
1,225,188
Messages
6,183,430
Members
453,160
Latest member
DaveM_26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top