Re: How to query
- From: "Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@xxxxxxxxxx>
- Date: Thu, 26 Apr 2007 08:05:04 +0200
Something like
SELECT n.acctno, n.name
FROM name AS n INNER JOIN data AS d ON n.acctno = d.acctno
WHERE EXISTS(SELECT * FROM data AS d1 WHERE d1.acctno = n.acctno AND
d1.bvalue = 'FORD')
AND NOT EXISTS (SELECT * FROM data AS d1 WHERE d1.acctno = n.acctno
AND d1.bvalue = 'CHEVY')
--
Dejan Sarka
http://blogs.solidq.com/EN/dsarka/
"Absolutely" <nospam@xxxxxxxxxxx> wrote in message
news:eh0FiP2hHHA.4064@xxxxxxxxxxxxxxxxxxxxxxx
New to this SQL query thing and have been playing. What I'm trying to do
is pull info conditionally through a query.
For example, say there are two tables named NAME and DATA. The two tables
are tied together with an account number. Within the DATA table there are
columns for Acctno, Avalue and Bvalue. So it would look something like
this:
For the table NAME:
Acctno Name
0001 Joe
0002 Jane
For the table DATA
Acctno Avalue Bvalue
0001 Car Ford
0001 Car Chevy
0002 Car Ford
0002 Car Dodge
What I'm trying to do is have a query to pull all the records in table
NAME that have Fords, but do not have a Chevy. So, in my example, even
though Joe has both a Ford and Chevy, he would not be pulled because he
has a Chevy. Jane would be pulled because she has a Ford, but does not
have a Chevy.
Make sense?
.
- References:
- How to query
- From: Absolutely
- How to query
- Prev by Date: Logistic regression prediction formula
- Next by Date: Re: Help using MDX
- Previous by thread: How to query
- Next by thread: Help using MDX
- Index(es):
Relevant Pages
|