Solved

Question about simple SQL query

Posted on 2008-06-16
3
168 Views
Last Modified: 2010-04-21
I am trying to only get records back when the inspector (lbal_inspectedby) is not the same as any of the inspectors in the query.  So,

SELECT * FROM LBAppraisalLocation WHERE lbal_appraisalid=xxxx AND lbal_inspectedby IS NOT THE SAME AS ANY OF THE OTHERS?????

So if the table looked like this
ID    lbal_appraisalid     lbal_inspectedby
1     4000                     2
2     4000                     14
3     4000                     2

then my query should only return
ID    lbal_appraisalid     lbal_inspectedby
1     4000                     2
2     4000                     14

How can I do this?
0
Comment
Question by:saturation
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21797122
not knowhing the exact column names...
select id, lbal_appraisalid, lbal_inspectedby 
  from LBAppraisalLocation l
 where lbal_appraisalid = xxxx
   and not exists ( select null from LBAppraisalLocation i 
                     where i.lbal_appraisalid = l.lbal_appraisalid
                       and i.lbal_inspectedby = l.lbal_inspectedby 
                       and i.id < l.id 
                )

Open in new window

0
 
LVL 7

Expert Comment

by:garethh86
ID: 21797181
SELECT DISTINCT(lbal_inspectedby), *  WHERE Lbal_appraisalid=@appraisalid FROM LBAppraisalLocation

Hope this helps!
0
 

Author Closing Comment

by:saturation
ID: 31467743
Great!  Worked like a charm.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question