Re: How to query

Tech-Archive recommends: Fix windows errors by optimizing your registry



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?






.



Relevant Pages

  • Re: More engine pictures
    ... I used to be able to pull the 283 out of my Comet (yep, chevy in a Ford!) in less than an hour. ...
    (rec.crafts.metalworking)
  • How to query
    ... New to this SQL query thing and have been playing. ... columns for Acctno, Avalue and Bvalue. ... but do not have a Chevy. ... Joe has both a Ford and Chevy, he would not be pulled because he has a ...
    (microsoft.public.sqlserver.datamining)
  • Re: House bigs spending tax bucks on autos: Rangel spent $777 a month for lease on Cadillac
    ... who doled out $147 a month for a Chevy Impala. ... legally use their office budgets to lease vehicles. ... he once tooled around in a Ford Escape hybrid. ... _Leonard Boswell, $6,298.56, D-Iowa, Chrysler Town & Country ...
    (soc.retirement)
  • Re: Ford or Chevy?
    ... For the rest of the group it's still Ford or Chevy? ... John, who really does reprogram a few selected GM PCMs, the 8051 being ... That's the last pre-OBD-2 'Vette/9C1 PCM. ...
    (rec.outdoors.rv-travel)
  • Re: AMD 64/PCI-Express and powerful system...
    ... Ford or Chevy) will not be obsolete in two or three months as the chip will. ... the AMD 64 is rather like a new technology automotive ... engine that will be the fastest engine in the world -- someday, ...
    (microsoft.public.windowsxp.hardware)