I need to retrieve ListingId from the below table based on the search condition. Kindly help the best way to retrive the query for the conditions below
Note : ListingId can have any number of ExtrafieldId, So Searching ListingId is based on the dynamic ExtrafieldId
If (ExtrafieldId = 1 and Value = 1) => OUTPUT - 20, 22
If (ExtrafieldId = 1 and Value = 1) and (ExtrafieldId = 2 and Value = 7) => OUTPUT - 21
If (ExtrafieldId =4and Value = 1999) => OUTPUT - 20, 21, 23
and so on…
ListingId ExtraFieldId Value
20 1 1
20 2 4
20 3
20 4 1990
21 1 2
21 2 7
21 3
21 4 1990
22 1 1
22 2 4
22 3
22 4 2000
23 1 NULL
23 2 NULL
23 4 1999
If you need 3 conditions, you’ll need to join the table to itself one more time (so 3 times in total)