Forum Moderators: open

Message Too Old, No Replies

Using a WHERE with LEFT JOIN

         

JMusic

5:56 am on Dec 11, 2006 (gmt 0)

10+ Year Member



My problem seems pretty simple, but I'm having a tough time figuring out a SELECT statement that will do what I want.

Basically, I have two tables that look like this:


table1
userid
1
2
3
4
5
6
7


table2
myid . . .addedid
2 . . . . 4
2 . . . . 5

What i need to do is find a way to list the users in table1 that are NOT listed in 'addedid' in table two.

This is the basic select statement that I'm using:

SELECT table1. * , table2. * FROM table1 LEFT JOIN table2 ON table1.userid = table2.addedid

Which lists the results like this:


userid . . myid . . addedid
1 . . . . .null . . null
2 . . . . .null . . null
3 . . . . .null . . null
4 . . . . .2 . . . .4
5 . . . . .2 . . . .5
6 . . . . .null . . null
7 . . . . .null . . null

What I want to do is display only the results that have "myid" and "addedid" as null. I tried adding "WHERE users.userid!=adds.addedid" to the original SELECT statement's ending, but it doesn't work. I also tried adding "WHERE "myid=null", but that doesn't work either. How can I achieve the result that I want?

[edited by: JMusic at 5:59 am (utc) on Dec. 11, 2006]

zCat

8:12 am on Dec 11, 2006 (gmt 0)

10+ Year Member



SELECT table1. * FROM table1 LEFT JOIN table2 ON table1.userid = table2.addedid WHERE table2.addedid IS NULL