Find the odd one out - Urgent

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
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Find the odd one out - Urgent

Post by Stryks »

Hi all,

I have two database tables that should have the same number of values in them, but one has one value too many.

I need to find a query which can tell me which one is not in both tables.

Can anyone tell me how to do this?

The value which should match for both is category_id

Thanks
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Hmmm.

Code: Select all

SELECT * FROM table, table2 WHERE table1.value <> table2.value
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

Well ... thats what I thought.

There are 2847 in one table and 2848 in the other. Using that query returns 8128201 values.

Go figure.

Any other ideas?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

Code: Select all

SELECT big_table.*, small_table.* FROM big_table LEFT JOIN small_table ON big_table.id = small_table.id WHERE small_table.id IS NULL
Post Reply