3
\$\begingroup\$

Essentially I'm attempting to select the top read (based on read_date), and check if it has a type in ( 'R','S','C','B','Q','F','I','A')

select *
from (
 select *
 from (
 select *
 FROM table
 WHERE id = 369514
 order by read_date desc
 )
 where rownum = 1
 )
 where type IN ( 'R','S','C','B','Q','F','I','A')

I only need to return a row if the top row has a type in the set, if not return nothing.

The only way I seem to be able to is using all these nasty sub-queries.

Malachi
29k11 gold badges86 silver badges188 bronze badges
asked Oct 28, 2013 at 16:20
\$\endgroup\$
2
  • \$\begingroup\$ is this Query slow? is it inefficient? \$\endgroup\$ Commented Oct 29, 2013 at 13:51
  • \$\begingroup\$ not slow, just looked like it could probably be improved \$\endgroup\$ Commented Oct 29, 2013 at 21:06

1 Answer 1

3
\$\begingroup\$

I was looking at the Query and you should be able to get rid of the outside Select.

select *
from (
 select *
 FROM table
 WHERE id = 369514
 order by read_date desc
 )
where rownum = 1 AND type IN ( 'R','S','C','B','Q','F','I','A')

I don't have anything to Test against, but it looks like this would work.

answered Oct 29, 2013 at 13:55
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I've actually realised this myself and removed it. I've upvoted :-) \$\endgroup\$ Commented Oct 29, 2013 at 21:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.