Do MySQL ignore "The" from the beginning of the LIKE clause?

I have a list of company names and want to display all the names starting with a specific character. deg.

So the request

SELECT * FROM company WHERE name LIKE 'd%'

But I also want companies starting with "The" so

SELECT * FROM company WHERE name LIKE 'd%' OR name LIKE 'The d%'

But now a tricky bit, when we get to 't', I want to delete all those that start with 'The' while saving others starting with 't' (and also keeping something like "The Truffle House", where the word " The "starts with" t ").

Any ideas? I would like to keep the logic in MySQL ...

+3
source share
3 answers
SELECT  *
FROM    company
WHERE   (name LIKE '?%' AND NOT name LIKE 'The %')
        OR name LIKE 'The ?%'
+1
source

Try:

SELECT * FROM company WHERE name regexp '^(The)d'
+1
source

Thanks for the answers I just selected for this.

SELECT  *
FROM    company
WHERE   (name LIKE '?%' AND NOT name LIKE 'The %')
        OR name LIKE 'The ?%'

for tI just made a long list NOT LIKE, so

AND (company_name LIKE 'The%t' OR company_name LIKE 't%') AND company_name NOT LIKE 'The a%' AND company_name NOT LIKE 'The b%' etc.

0
source

Source: https://habr.com/ru/post/1784774/


All Articles