Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Query Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-08, 22:52
lovelandj lovelandj is offline
Registered User
 
Join Date: Oct 2008
Posts: 1
Query Help

Hello,
I am trying to get list of students who don't have sibling in one building.

Below is my query.

When I take out the Not in the Not In statement I get data to return. It gives me the list of students that have siblings in the other building. I would like the opposite.

I am just learning to SQL queries at the beginners stage.

Thank you for your help.
Jeremy


SELECT
s.LASTFIRST,
s.FAMILY_IDENT,
s.SCHOOLID

FROM Students s

WHERE ( s.ENROLL_STATUS = 0
AND s.schoolID IN (2,3,4)
AND s.FAMILY_IDENT Not IN ( SELECT DISTINCT s.Family_Ident
From Students s
WHERE S.SchoolId = 2
)
)

ORDER BY
s.LASTFIRST
Reply With Quote
  #2 (permalink)  
Old 10-16-08, 15:17
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 1,951
Talking

You have the same table "alias" on both the query and sub-query, try changing this:
Code:
-- etc -- AND s.FAMILY_IDENT Not IN ( SELECT DISTINCT F.Family_Ident From Students F WHERE F.SchoolId = 2 ) --etc --
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 10-17-08, 07:43
lwms lwms is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
Hi, lovelandj. Maybe none of the students has any sibling in the other building. Try to check the data in the Students table.
Reply With Quote
  #4 (permalink)  
Old 10-20-08, 06:04
hikrishna007 hikrishna007 is offline
Registered User
 
Join Date: Oct 2008
Posts: 2
Check the data

your query might be correct. there might not be any sibling in the building which u r looking for
Reply With Quote
  #5 (permalink)  
Old 10-20-08, 06:19
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,131
Another potential solution
Code:
SELECT s.lastfirst , s.family_ident , s.schoolid FROM ( SELECT * FROM students WHERE schoolid IN (2, 3, 4) ) s LEFT JOIN ( SELECT * FROM students WHERE schoolid IN (2) ) s2 ON s.family_ident = s2.family_ident WHERE s2.family_ident IS NULL ORDER BY s.lastfirst
__________________
George
You only stop learning when you stop asking questions.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On