Search code examples
mysqlsqlsql-like

MySQL Workbench. How to have multiple conditions using LIKE, OR, AND


Is there any way to split up the expressions using the Like,OR, and AND operators. I am trying to use parenthesis to split my expressions, but I either get "Truncated incorrect DOUBLE value" or "Truncated incorrect INTEGER value" errors.

I want to have my statement to be almost set up like this,

((statement LIKE (This or This)

AND statement LIKE This))

OR statement LIKE this

DELETE FROM ap.vendor_contacts 
WHERE
    ((last_name LIKE 'd%' OR '%s')
    AND first_name LIKE 'm%')
    OR first_name LIKE '%al%'

Solution

  • You have a Syntax error. You cannot use LIKE operator as: <fieldname> LIKE <value1> OR <value2>. It has to be as follows:

    <fieldname> LIKE <value1> OR <fieldname> LIKE <value2>

    Do the following instead:

    DELETE FROM ap.vendor_contacts 
    WHERE
        ((last_name LIKE 'd%' OR last_name LIKE '%s')
        AND first_name LIKE 'm%')
        OR first_name LIKE '%al%'