Skip to content
Advertisement

How to write sql query to get this result

I had two tables as below:

request_id update_from_id sw_ref_number raised_by_user_id raised_date
1 0 1 3 2019-08-29 15:08:16.000
id request_id input_id value is_deleted
21 1 1 00001 0
22 1 2 3 0
75 2 1 00002 0
76 2 2 0

My query is:

And after that my result is:

request_id sw_ref_number value input_id
1 1 00001 1
1 1 3 2
2 2 00002 1
2 2 2

I want a result as:

request_id sw_ref_number epi_db_no manuf_no
1 1 00001 3
2 2 00002

Here input_id = 1 means epi_db_no and input_id = 2 means manuf_no.

How can I get this?

Thanks

Advertisement

Answer

You can do it using self-join like the following query.

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