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.

\$\endgroup\$
  • \$\begingroup\$ is this Query slow? is it inefficient? \$\endgroup\$ – Malachi Oct 29 '13 at 13:51
  • \$\begingroup\$ not slow, just looked like it could probably be improved \$\endgroup\$ – m.edmondson Oct 29 '13 at 21:06
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.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ I've actually realised this myself and removed it. I've upvoted :-) \$\endgroup\$ – m.edmondson Oct 29 '13 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.