Simple query help please

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cybercog
Forum Newbie
Posts: 20
Joined: Sat Oct 06, 2007 10:35 pm

Simple query help please

Post by cybercog »

Two tables:

t1 = a list of ID's as int (1 - 100)

t2 = a list of ID's from t1 that get used during a year (2,4,6,8,9,20)

How do I get a list of ID's from t1 that are NOT also listed in t2? (the ones unused in t1)

I can easily get it when I want the ones used, but the unused is not working right.

Thanks
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Simple query help please

Post by Apollo »

SELECT id FROM t1 WHERE NOT id IN (SELECT id FROM t2)

Just curious: if you had difficulty selecting the unused ones, but you were able to easily select the used ones, how did you do it?
cybercog
Forum Newbie
Posts: 20
Joined: Sat Oct 06, 2007 10:35 pm

Re: Simple query help please

Post by cybercog »

Thanks, that worked great.

I just did a simple SELECT on the two tables and compared id's

I've got to study more, that's for sure.

Thanks
Post Reply