SQL Oracle rownum on multiple where clauses?
WITH numbered_equipment AS ( SELECT t.*, ROW_NUMBER() OVER( PARTITION BY EQUIPMENT ORDER BY NULL ) AS row_num FROM MYTABLE t WHERE EQUIPMENT IN ( 'KEYBOARD', 'MOUSE', 'MONITOR' ))SELECT *FROM numbered_equipmentWHERE row_num <= 2;
If you want to prioritize which rows are selected based on other columns then modify the ORDER BY NULL
part of the query to put the highest priority elements first in the order.
Edit
To just pull out rows where the equipment matches and the status is active then use:
WITH numbered_equipment AS ( SELECT t.*, ROW_NUMBER() OVER( PARTITION BY EQUIPMENT ORDER BY NULL ) AS row_num FROM MYTABLE t WHERE EQUIPMENT IN ( 'KEYBOARD', 'MOUSE', 'MONITOR' ) AND STATUS = 'Active')SELECT *FROM numbered_equipmentWHERE row_num <= 2;