Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

SQL Query where name like with multiple name prefix

I have to write a SQL Query where the Column Name prefix conditions for multiple names ..

Example

Select * from Table
where column like 'NY%'
OR
Select * from Table
where column like 'NZ%'
OR
Select * from Table
where column like 'NX%'
OR
Select * from Table
where column like 'NW%'

I wonder, whether there is one query to accomplish multiple prefix characters in an optimized manner ..
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

Thanks Brian .. Is that the only option .. How about query performance ?
Avatar of chokka

ASKER

Thanks
You could try something like...

SELECT *
FROM Table
WHERE LEFT(column, 2) IN ('NY', 'NZ', 'NX', 'NW')

The only way you could speed it up a bit is to create an index on the target column