Match ANY versus ALL
suggest changeLIKE ANY and LIKE ALL with a parenthesized list are PostgreSQL syntax, not standard SQL.
Match any: the value must match at least one pattern. In this example the product type must be ‘electronics’, ‘books’, or ‘video’.
SELECT *
FROM purchase_table
WHERE product_type LIKE ANY ('electronics', 'books', 'video');
Match all (must meet all requirements). In this example both ‘united kingdom’ and ‘london’ and ‘eastern road’ (including variations) must be matched.
SELECT *
FROM customer_table
WHERE full_address LIKE ALL ('%united kingdom%', '%london%', '%eastern road%');
Negative selection: Use ALL to exclude all items. This example yields all results where the product type is not ‘electronics’ and not ‘books’ and not ‘video’.
SELECT *
FROM customer_table
WHERE product_type NOT LIKE ALL ('electronics', 'books', 'video');
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents