Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select all from one table that do not match few from other table

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
I need help forming a query. I have two tables; country and country_restricted

'country' lists all countries on this great earth. 'country_restricted' lists only those countries that we want to restrict for a peticular reason

Here's how the tables are set up:
country:
country_id | country_name

country_restricted:
country_id

I figured out how to query for only the restricted countries, which is like this:

SELECT a.country_id, a.country_name
FROM country a
RIGHT JOIN country_restricted b
ON a.country_id = b.country_id

I want to do a query that will display only those countries from the 'country' table that are not listed in the 'country_restricted' table.

Anyone know how to do this?
 
Check out this thread: thread183-762400

--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
Thanks Angel,

You are one.

Here's what worked for me:

SELECT a.country_id, a.country_name
FROM country a
WHERE NOT EXISTS
(SELECT b.country_id
FROM country_restricted b
WHERE b.country_id = a.country_id)
ORDER BY country_display
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top