Subtracting Joins

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
bdeonline
Forum Commoner
Posts: 42
Joined: Sun Jul 18, 2004 10:45 am

Subtracting Joins

Post by bdeonline »

How can I do a Join that if the id's are the same those with equal id's won't display.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

I'm not sure to understand your question, a join is made when you take a value that equals another one.. that's how you actually join.
Is it a join you want to do ?
bdeonline
Forum Commoner
Posts: 42
Joined: Sun Jul 18, 2004 10:45 am

Post by bdeonline »

It may not be a Join then but some how I got to have all the rows from one table except the ones with matching id numbers from another
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[mysql_man]left join[/mysql_man]

Code: Select all

SELECT * FROM table1 LEFT JOIN table2 ON table2.id = table1.id WHERE table2.id IS NULL
or similar....
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Post by Calimero »

Just an idea, haven't tested it:

SELECT * from * where table1.id != table2.id
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

I though what you asked was somehting like

Code: Select all

SELECT * FROM table1, table2 WHERE t1.id <> t2.id
mhh it might not even work.. as a rules of thumb.. ALWAYS follow feyd advices :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=24104&highlight=left+join+null
may help point out what's the deal with it..
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

feyd wrote:LEFT JOIN looks at the data to it's left, heh, and if it doesn't match, all fields that'd normally be set, are set to NULL. So you filter it where those rows are null.. where the tables don't match..
Everything is clear
thx
Post Reply