chokka
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 ..
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER