patternsqlMinor
Oracle nested query
Viewed 0 times
nestedoraclequery
Problem
Essentially I'm attempting to select the top read (based on
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.
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.
Solution
I was looking at the Query and you should be able to get rid of the outside Select.
I don't have anything to Test against, but it looks like this would work.
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.
Code Snippets
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')Context
StackExchange Code Review Q#33407, answer score: 3
Revisions (0)
No revisions yet.