December 19, 2007 at 2:32 pm
I'm a little lost on where to start. I have two tables:
Table11..........Table2
Name.............ID1
ID.................ID2
....................Link
All I want to do is list all the names from Table1 where:
Table1.ID <> Table2.ID1
AND
Table1.ID <> Table2.ID2
Sounds easy, but I'm very new to SQL in general and can't get the results at all. Any help in the right direction would be great.
December 19, 2007 at 2:38 pm
select t1.name
from table1 t1
where t1.id not in (select id1
from table2
union
select id2 from table2)
Might be able to make it run better or clean it up, but I think this is what you're asking.
December 19, 2007 at 4:01 pm
That was what I needed. A few tweaks but it works great...thank you.
December 19, 2007 at 4:13 pm
What were the "tweaks"?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 25, 2007 at 8:01 pm
select name
from table1 a
where not exists(select 1 from table2 where id1=a.id and id2=a.id)
December 27, 2007 at 1:28 am
Since the title is "where to start" ...
Start using aliasses everywhere to avoid confusion.
(occurs especialy after query maintenance !)
select name
from table1 a
where not exists(select 1 from table2 T2 where T2.id1=a.id and T2.id2=a.id)
The query you've provided is not symanticaly the same as the one Steve provided !
If you want the same result as Steve, you should use :
where T2.id1=a.id OR T2.id2=a.id)
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
December 31, 2007 at 8:54 am
I just had some additions to the Where statemnt to filter certain items in the first database.
Thanks Again
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply