×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Compound SQL query

Compound SQL query

Compound SQL query

(OP)
Hi,

I'm just starting with SQL and have quite a basic question.

I have a table People with the following fields:
PersonID, Name, CountryID

Sample data:
1   Bob   4
2   Jim   5
3   Bill  5

A Countries table with the following fields:

CountryID, Name, ContinentID

Sample data:
4   USA   1
5   UK    2

And a Continents table with the following fields:
ContinentID, Name

Sample data:
1   North America
2   Europe

Now I want to submit a query that will return the names of all the people in Europe.

I was thinking that this would be along the lines of:

CODE

SELECT Name FROM People WHERE CountryID=(SELECT ContinentID FROM Countries WHERE ContinentID=2)

But this doesn't seem to work - where have I gone wrong? With my sample data above the query should return Jim and Bill.

Many, many thanks,

Froskoy.

RE: Compound SQL query

CODE

SELECT People.Name
  FROM Continents
INNER
  JOIN Countries
    ON Countries.ContinentID = Continents.ContinentID
INNER
  JOIN People
    ON People.CountryID = Countries.ContinentID
 WHERE Continents.Name = 'Europe'
smile

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close