Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Statement Problem 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
US
I first need to apologize for my subject. I didn't know exactly how to describe my problem in the Subject.

I have the following fields:

ID TEST TERM
1 1-1 1028
1 1-2 1034

2 1-1 1028
2 2-1 1034

3 1-1 1048
3 2-1 1058

I need to write a select statement that selects all IDs in term 1034 (the term will change so I have a prompt) and then also the other terms for the same ID so my results would only retrieve the data for ID 1 and 2.

Note: I'm using a reporting tool that doesn't allow me to have a from statement in expressions or write views so I hope what I need is still possible.

Help is very appreciated.
 
Try this:
Code:
SELECT t2.*
FROM my_table t1, my_table t2
WHERE t1.id = t2.id
  AND t1.term = 1034;
My test sample looks like this:
Code:
SQL> select * from my_table;

        ID TEST             TERM
---------- ---------- ----------
         1 1-1              1028
         1 1-2              1034
         2 1-1              1028
         2 2-1              1034
         3 1-1              1048
         3 2-1              1058

6 rows selected.

SQL> select t2.*
  2  from my_table t1, my_table t2
  3  where t1.id = t2.id
  4  and t1.term = 1034;

        ID TEST             TERM
---------- ---------- ----------
         1 1-1              1028
         1 1-2              1034
         2 1-1              1028
         2 2-1              1034
 
Thank you carp. Your statement worked wonderfully.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top