I have a SQL Server query which takes data from Oracle 8i server using linked server connection. My question here is completely on Oracle SQL.
There is a StyleSizes table. One style can have one or more sizes associated with it. I need to find any one Style_CD which has more than one Size_CD. This can be achieved by GROUP BY and HAVING. But I need only one such style. The volume of the table is so big that I cannot wait till the query execution is complete – so I need only one style.
How to get only one record quickly after applying GROUP BY and HAVING clauses in Oracle?
SELECT STYLE_CD
FROM OPENQUERY(LinkedORAServer,
'SELECT STYLE_CD
FROM DA.StyleSize M
GROUP BY STYLE_CD
HAVING COUNT(SIZE_CD) > 1
')
FURTHER READING
- Ask Tom - On ROWNUM and Limiting Results
- Limit - Comparison of different SQL implementations
- How do I limit the number of rows returned by an Oracle query after ordering?
- Row Limiting Clause for Top-N Queries in Oracle Database 12c Release 1 (12.1)
- SQL Server - Pagination with OFFSET / FETCH : A better way