Solved

Question about simple SQL query

Posted on 2008-06-16
3
170 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 143

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SubQuery link 4 43
Currency in SQL? 2 43
Convert string date and select older than 30 days from today 2 40
SQL Query Syntax Assistance 2 34
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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