|
Home > Archive > Microsoft SQL Server forum > June 2005 > SQL query to check against a list
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SQL query to check against a list
|
|
| Jeffrey Sheldon via SQLMonster.com 2005-06-15, 1:24 pm |
| SQL gurus...
I have one table of items that is the master file. We will call this Table A.
I have another table that contains few, some or all items from Table A. We
will call this Table B.
I want to run a query that compares the list of items on Table B against the
master list on Table A.
If the item is not present on Table B, show it in the SQL results.
Best way to achieve this? I am looping and doubling results in my sql tries.
Jeff
--
Message posted via http://www.webservertalk.com
| |
| Simon Hayes 2005-06-15, 1:24 pm |
|
"Jeffrey Sheldon via webservertalk.com" <forum@nospam.webservertalk.com> wrote in
message news:4FE4E238FCBD0@w
ebservertalk.com...
> SQL gurus...
>
> I have one table of items that is the master file. We will call this
> Table A.
>
>
> I have another table that contains few, some or all items from Table A.
> We
> will call this Table B.
>
> I want to run a query that compares the list of items on Table B against
> the
> master list on Table A.
>
> If the item is not present on Table B, show it in the SQL results.
>
> Best way to achieve this? I am looping and doubling results in my sql
> tries.
>
> Jeff
>
> --
> Message posted via http://www.webservertalk.com
If you want all the items in A which do not have a corresponding row in B,
then this should work:
select
a.col, a.col2, ...
from
dbo.a a
where
not exists (
select *
from dbo.b b
where a.keycol = b.keycol)
Simon
|
|
|
|
|