OK - I'm using SQL server 2000 and I need help with a query:
Here are the tables and info:
users:
id | name
1 | mark
2 | bill
3 | jack
4 | liz
5 | jeff
selected:
id | selected
1 | 1
3 | 1
5 | 1
This is obviously simplified but the id in the selected table corresponds to the user in the users table. I want a query that selects all the users in users table and selects a 1 if the user is selected and a null value if there is no entry in table_2.
here's what I have now:
select U.name, S.selected from users as U, selected as S where U.id=S.id
this will only return the users mark, jack and jeff. I want to return all the users and have the selected field be NULL if there isn't an entry in the selected table. The result set I want is
name | selected
mark |1
bill |NULL
jack |1
liz |NULL
jeff |1
I think that I need a left join for this. Any help would be very much appreciated.