Querying a table for specific tuples (pairs of values) using the "IN" clause requires careful consideration. While string concatenation may seem like a viable solution, it can be computationally expensive for large datasets. Fortunately, there's a more efficient approach using Standard SQL-92 syntax.
The proposed syntax with minor tweaks (("'"). replaced with (''). and (VALUES keyword added) is a valid Standard SQL-92 syntax:
SELECT * FROM mytable WHERE (group_id, group_type) IN ( VALUES ('1234-567', 2), ('4321-765', 3), ('1111-222', 5) );
However, it's important to note that SQL Server 2022 does not yet support this syntax, considering it an "unplanned" feature. Conversely, PostgreSQL and SQLite are among the SQL products that do support it.
The above is the detailed content of How Can I Efficiently Query for Specific Tuples Using SQL's 'IN' Clause?. For more information, please follow other related articles on the PHP Chinese website!