Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using SELECT MAX(Substr( in a subquery to return specific rows

kmc5117Dec 20 2010 — edited Dec 20 2010
Oracle v10

Here's an example of a query and the output
SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 WHERE SAMPLEID = 'IA 0005 0166';

86907	IA 0005 0166	IA 0005	R2004:001160	2004
98158	IA 0005 0166	IA 0005	R2005:000956	2005
I am attempting to only return the newest row of data, in this case the 2005 row.

I tried
SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 
WHERE SAMPLEID = 'IA 0005 0166' AND
REQUISITION IN 
(SELECT MAX(SUBSTR(REQUISITION,2,4)) FROM SEARCH PL2 
WHERE SUBSTR(PL2.REQUISITION,2,4) = SUBSTR(PL1.REQUISITION,2,4));
But it returns no results. I feel I am missing something simple.

TIA
This post has been answered by odie_63 on Dec 20 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 17 2011
Added on Dec 20 2010
2 comments
3,453 views