Skip to content
Advertisement

Oracle SQL: select from a set of orders only those that contain certain types

I want to select from a set of orders only those that are marked with certain types.

Example:

Let’s assume I have a table X.

In my case I want to select only those orders that contain both A and B:

My work so far:

However, I don’t like this solution. Is there a better approach?

Advertisement

Answer

Use an analytic function:

Which, for the sample data:

Outputs:

ORDER_NO | TYPE
-------: | :---
     123 | A   
     123 | B   
     123 | C   
     567 | A   
     567 | B   

db<>fiddle here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement