Combining OR function in LIKE

Why can’t the OR feature work using LIKE?

WORKS:

USE invoicing;
SELECT *
from clients
WHERE address LIKE ‘%parkway%’ OR address LIKE ‘%road%’

Doesn’t work: Why?

USE invoicing;
SELECT *
from clients
WHERE address LIKE (‘%parkway%’ OR ‘%road%’)

Every language makes choices on what forms of syntax they will accept. Some of those decisions just make the grammar easier to work with. In SQL, both sides of an OR expression need to resolve to a boolean (ie. they must resolve to TRUE or FALSE). In the working version, the OR is connecting the expressions address LIKE '%parkway%' (which resolves to a boolean) and address LIKE '%road%' (which also resolves to a boolean). In contrast, the option you have written has two sides that both resolve to strings ('%parkway%' and '%road%') rather than booleans. While it is possible for a language to be created which supports that kind of syntax, I do not know of any SQL language which does.

NOTE: Many versions of SQL also have full regular expression support so you can write something like address REGEXP 'parkway|road' to accomplish what you want (just know that support for regular expressions varies with each SQL engine).

1 Like

On MariaDB, I got this working

SELECT * FROM clients
WHERE address RLIKE  'parkway|road' ;
2 Likes