Skip to content
Advertisement

How to get list of ids into separate column

Problem statement: I have a table master_tab which consist of two columns e_id and owner_id. I want to list down the e_id’s which belong to owner_id 72 and 73. There is another condition that analysis_comp flag should be 1 in the table transaction_tab.

My attempt:

Tool used: SQL Developer(18c)

Current Output:

Expected Output:

Is it possible to get only the list of e_id when owner_id is 72 then in the first row it should give all the list of e_id whose owner_id is 72, Likewise, if owner_id is 73 then it should provide a separate list of e_id into another column? If I use the JOIN condition, it will restrict only to owner_id 72. Is there any other way to handle such scenarios where we need list of ids from the same table in different columns

Advertisement

Answer

@Vicky, this version is modified from you query and may be more comfortable for you.

This version used ROWNUM for each subquery, then match the 2 columns row-by-row.

Why we have used row_number / rownum? Because you are joining the 2 columns using row number.

In SQL (or any table based output), it is generally expected that the data in a row is related to each other. You presentation may be confusing to those accustomed to this. Why not output separately?

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