How to write an SQL statement to use "LIKE" for nine different values? [duplicate] How to write an SQL statement to use "LIKE" for nine different values? [duplicate] sql sql

How to write an SQL statement to use "LIKE" for nine different values? [duplicate]


I'm afraid you're stuck with:

  WHERE (FIELD2 LIKE '%value21' OR          FIELD2 LIKE '%value22' OR          FIELD2 LIKE '%value23' ...)

at least in standard SQL (your particular engine might offer some form of full-text indexing that would help).

A query like this often indicates a normalization problem in your database design with multiple values stored in a single field value. If that's true in your case and you have any degree of control over the database schema, I advise fixing the problem as soon as possible. Otherwise check your medical coverage to make sure it covers SQL-induced psychosis — this can drive you crazy.


One way:

select Field1, Field2 from Table where Field2 like '%val%'UNIONselect Field1, Field2 from Table where Field2 like '%val2%'UNIONselect Field1, Field2 from Table where Field2 like '%val2%'

etc.