Groups | Blog | Home
all groups > sql server full text search > january 2004 >

sql server full text search : Problem with a SQL Statement


Rohtash Kapoor
1/31/2004 12:01:02 PM
--The following will show records of all customers who haven't bought item
number 901.

SELECT * FROM Customers A
WHERE NOT EXISTS
(SELECT * FROM Link
WHERE CID = A.CID AND PID = 901)

--
Rohtash Kapoor
http://www.sqlmantra.com



[quoted text, click to view]

Atley
1/31/2004 2:24:37 PM
I have three tables:

Products Table
PID
PName
PType

Linking Table
LID
PID
CID

Customers Table
CID
CName
CPhone


I am trying to make a single statement that will give me all the customers
that haven't bought a certain single product so i can make a list of people
to contact regarding that product.

Any help or suggestions would be greatly appreciated... I just can't seem to
get this one right.

@


Jacco Schalkwijk
1/31/2004 7:43:41 PM
SELECT c.CName, c.Cphone
FROM Customers c
LEFT OUTER JOIN
(Linking l
INNER JOIN Products p
ON l.pid = c.pid)
ON c.CID = l.CID
AND p.PName = 'some product name'
WHERE l.CID IS NULL

or
SELECT c.CName, c.Cphone
FROM Customers c
WHERE NOT EXISTS(
SELECT NULL
FROM Linking l
INNER JOIN Products p
ON l.pid = c.pid
WHERE c.CID = l.CID
AND p.PName = 'some product name')

--
Jacco Schalkwijk
SQL Server MVP



[quoted text, click to view]

Kristofer Gafvert
1/31/2004 9:52:32 PM
I see you have got an answer.

But please next time, do not cross-post to every newsgroup you find. This is
not a Windows Server problem, nor a datamining or datawarehouse problem.

--
Regards,
Kristofer Gafvert - IIS MVP
Reply to newsgroup only. Remove NEWS if you must reply by email, but please
do not.
www.ilopia.com - FAQ and Tutorials for Windows Server 2003


[quoted text, click to view]

AddThis Social Bookmark Button