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!

Identify required row from group 1

Status
Not open for further replies.

josees

Technical User
Mar 12, 2008
2
US
Is there a way using SQL to extract only the following? My status is being pulled from another table that contains historical status information for this member. Any thoughs or ideas?

ID NAME STATUS
1232 JOHN DOE UNEXAMINED
1232 JOHN DOE EXAMINED
5555 JANE DOE UNEXAMINED
1232 JANE SMITH EXAMINED
9999 TOM JONES UNEXAMINED
9999 TOM JONES EXAMINED

Expected Results:
ID NAME STATUS
1232 JOHN DOE EXAMINED
5555 JANE DOE UNEXAMINED
1232 JANE SMITH EXAMINED
9999 TOM JONES EXAMINED


Thanks for any guidance!
 
Josees,

Welcome to both Tek-Tips and to the Oracle forums.

Your sample data show both "JOHN DOE" and "JANE SMITH" with the same ID. Is that an actual situation that you want the code to deal with, or is that simply "sample-data error"? (For the sake of sample code, I'll presume that "JANE SMITH" has an ID of 1233. [wink])

Code:
select * from josees;

  ID NAME       STATUS
---- ---------- ----------
1232 JOHN DOE   UNEXAMINED
1232 JOHN DOE   EXAMINED
5555 JANE DOE   UNEXAMINED
1233 JANE SMITH EXAMINED
9999 TOM JONES  UNEXAMINED
9999 TOM JONES  EXAMINED

select id, name, min(status) status
  from josees
 group by id, name;

  ID NAME       STATUS
---- ---------- ----------
1232 JOHN DOE   EXAMINED
1233 JANE SMITH EXAMINED
5555 JANE DOE   UNEXAMINED
9999 TOM JONES  EXAMINED
Let us know if this is what you wanted.


[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
You are correct about my typo, thanks! This works for exactly what I need, thanks again!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top