Home > Archive > Microsoft SQL Server forum > April 2005 > A query that chooses non-matching items









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 A query that chooses non-matching items
chudson007@hotmail.com

2005-04-27, 7:23 am

I've never been the most articulate person in the world, so i though
the best way to illustrate the script I am looking for help with, is to
provide you with two tables and the results I require.

Table 1
ProductName1 Product
Name2 Qty
AA AA-1 2
BB BB-1 3
CC CC-1 4


Table2
ProductName Qty
AA 2
BB-1 3
DD 6


Desired Results=09
ProductName Qty
DD 6
=09

Regards,
Ciar=E1n

Erland Sommarskog

2005-04-27, 9:23 am

(chudson007@hotmail.com) writes:
> I've never been the most articulate person in the world, so i though
> the best way to illustrate the script I am looking for help with, is to
> provide you with two tables and the results I require.
>
> Table 1
> ProductName1 ProductName2 Qty
> AA AA-1 2
> BB BB-1 3
> CC CC-1 4
>
>
> Table2
> ProductName Qty
> AA 2
> BB-1 3
> DD 6
>
>
> Desired Results
> ProductName Qty
> DD 6


SELECT t2.ProductName, t2.Qty
FROM Table2 t2
WHERE NOT EXISTS (SELECT *
FROM Table1 t1
WHERE t1.ProductName2 = t2.ProductName
AND t1.Qty = t2.Qty)

Or somesuch depending on your exact definition of "matching".


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com