Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
djavet
Starting Member
36 Posts |
Posted - 2005-03-18 : 10:39:26
|
| Hello,I've a query wich with I select buildings form a table.I've a second table with a few building I don't want in my select (exclude form select). How can I make this?Thx a lot.DomPS: I'm a sql newbie... |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-03-18 : 10:41:27
|
Just don't list the ones you don't want to select.Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
djavet
Starting Member
36 Posts |
Posted - 2005-03-18 : 10:45:52
|
I know that, but how? If I've 2 tables...Regards, Dom |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-03-18 : 10:56:34
|
| SELECT * FROM Table1 oWHERE NOT Exists (SELECT * FROM Table2 i where i.building = o.building)Brett8-) |
 |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-03-18 : 11:12:36
|
Sorry, Dom. Obviously I misunderstood you. Perhaps if you had provided a little more information, or maybe an example then I would have been able to better answer your question.My apologies.Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
Blastrix
Posting Yak Master
208 Posts |
Posted - 2005-03-18 : 12:02:48
|
quote: Originally posted by X002548 SELECT * FROM Table1 oWHERE NOT Exists (SELECT * FROM Table2 i where i.building = o.building)
Brett(or anyone),Just curious, is it better to do the way you listed, or to do one of the following? They all obtain the same results. Just in different ways.SELECT * FROM Table1 oLEFT JOIN Table2 i ON o.building = i.buildingWHERE i.building IS NULLor possiblySELECT * FROM Table1 oWHERE o.building NOT IN (SELECT building FROM Table2)Steve |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-18 : 12:05:04
|
there was already a discussion on that.i think the results were:for large tables1. left join 2. not exists3. not infor small tables1. not in2. not exists3. left join Go with the flow & have fun! Else fight the flow |
 |
|
|
djavet
Starting Member
36 Posts |
Posted - 2005-03-22 : 02:10:13
|
| Thx a lot!Dom |
 |
|
|
|
|
|
|
|