Two Laptop Bag*
The moose likes JDBC and the fly likes subqueries help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "subqueries help! " Watch "subqueries help! " New topic
Author

subqueries help!

bhavin ragha
Greenhorn

Joined: Mar 28, 2012
Posts: 17
i need to use subqueries, and list the names of the members of band Radiohead. Assume you do
not know the band_id of Radiohead.

table info:
bands(band_id, band_name) represents a list of bands

band_members(band_id, name, dob, country, sex) represents the members of the
bands in relation bands

here is what i have so far
SELECT band_members.name
FROM band_members
WHERE band_members.name in (SELECT bands.band_name
FROM bands
WHERE bands.band_name = 'Radiohead');
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

SELECT band_members.name
FROM band_members
WHERE band_members.name in (SELECT bands.band_name <-- Incorrect
FROM bands
WHERE bands.band_name = 'Radiohead');

This would look for band member name as 'Radiohead'.

You need to use the band_id (hint).

Try it.. I'll help.

Pat.
bhavin ragha
Greenhorn

Joined: Mar 28, 2012
Posts: 17
William P O'Sullivan wrote:SELECT band_members.name
FROM band_members
WHERE band_members.name in (SELECT bands.band_name <-- Incorrect
FROM bands
WHERE bands.band_name = 'Radiohead');

This would look for band member name as 'Radiohead'.

You need to use the band_id (hint).

Try it.. I'll help.

Pat.


oh i see... thank you!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: subqueries help!
 
Similar Threads
Correlated subqueries in HQL Select Clause
matching rows from one table to another
out putting a table but putting null in the rows where the attributes are not listed. (outer join)
inner / sub / inline query
The dreaded null pointer exception