×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Retrieve records if they meet a certain criteria (1 record is <1000 and the other one >=1000)
2

Retrieve records if they meet a certain criteria (1 record is <1000 and the other one >=1000)

Retrieve records if they meet a certain criteria (1 record is <1000 and the other one >=1000)

(OP)
Two tables

COMBINED

term
id
number


CLASS

term
dept
catalog
number


DATA IN COMBINED

term id number
1154 5555 10121
1154 5555 9587
1154 44444 5698
1154 44444 99999

DATA IN CLASS

term dept catalog number
1154 ART 1000 10121
1154 ART 101 9587
1154 ART 2000 5698
1154 ART 3000 99999

WHAT data needs to be retrieved

I only want data retrieved for records if they have the same combined.id and 1 record has a catalog# less than 1000 and 1 record has a catalog# greater or equal to 1000 so for the above data only the following is retrieved since combined.id 5555 meets the criteria. combined.id 44444 does not meet the criteria because both records have catalog#s greater or equal to 1000

term dept catalog id number
1154 ART 1000 5555 10121
1154 ART 101 5555 9587

Help is VERY appreciated.

RE: Retrieve records if they meet a certain criteria (1 record is <1000 and the other one >=1000)

This will return the combined row where there is one and only one row in class where the catalog is below 1000 and there is one and only one row in class where the catalog is greater then or equal to 1000.

CODE -->

SELECT *
  FROM Combined A
 WHERE     EXISTS
               (  SELECT Catalog
                    FROM Class B
                   WHERE A.Term = B.Term AND B.Catalog < 1000
                GROUP BY Catalog
                  HAVING COUNT (*) = 1)
       AND EXISTS
               (  SELECT Catalog
                    FROM Class B
                   WHERE A.Term = B.Term AND B.Catalog >= 1000
                GROUP BY Catalog
                  HAVING COUNT (*) = 1); 

Bill
Lead Application Developer
New York State, USA

RE: Retrieve records if they meet a certain criteria (1 record is <1000 and the other one >=1000)

(OP)
Thanks Bill. I will try it out.

RE: Retrieve records if they meet a certain criteria (1 record is <1000 and the other one >=1000)

CODE

SELECT ca.term, ca.dept, ca.catalog, c1.cnumber
FROM  class ca
      INNER JOIN combined c1
         ON ca.cnumber = c1.cnumber
            AND ca.term = c1.term
      INNER JOIN combined c2
         ON c1.id = c2.id
            AND c1.term = c2.term
      INNER JOIN class cb
         ON c2.cnumber = cb.cnumber
            AND c2.term = cb.term
WHERE (ca.catalog < 1000 AND cb.catalog >= 1000)
      OR (cb.catalog < 1000 AND ca.catalog >= 1000) 

Please note that where you are calling for a column called "number", I have used cnumber. Oracle won't let me create a table with column named after a reserved word.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close