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
You can use union and distinct quite easy for this. If you're using the ListingId as an input to another query using an IN-clause you don't have to mind the duplicates otherwise you can add
SELECT DISTINCT ListingId FROM (
SELECT
ListingId
... -- the rest from below
) AS Data
Here's the query to get the listing (with possible duplicates!):
SELECT
ListingID
FROM
TABLE_NAME
WHERE
ExtrafieldId = 1 and Value = 1
UNION ALL
SELECT
ListingID
FROM
TABLE_NAME
WHERE
ExtrafieldId = 1 AND Value = 1 AND ExtrafieldId = 2 and Value = 7
UNION ALL
SELECT
ListingID
FROM
TABLE_NAME
WHERE
ExtrafieldId = 4 AND Value = 1999