How to select rows from table that matches where clause on two columns? I came up with below query. Please advice if there is better way with less text.
SELECT name, number
FROM namenumber
WHERE name IN (“Car”) AND number = “1234"
UNION
SELECT name, number
FROM namenumber
WHERE name IN ("Train") AND number = "5678"
UNION
SELECT name, number
FROM namenumber
WHERE name IN ("Flight") AND number = "9012";
CodePudding user response:
SELECT name, number FROM namenumber
WHERE (name, number) IN (
(“Car”,“1234"), ("Train", "5678"), ("Flight", "9012")
) ;
CodePudding user response:
Could be just like this this
SELECT name, number FROM namenumber
WHERE (name in (“Car”) and number = “1234") OR
(name in ("Train") and number = "5678") OR
(name in ("Flight") and number = "9012")