Link to home
Start Free TrialLog in
Avatar of Arkawa72
Arkawa72Flag for Netherlands

asked on

Sql select query

I have a question about a select query.
I have a table with three columns (NAME, CITY, COUNTRY)
I would like to select all rows except the USA, But I would like to include New York City.

How can I do this in one select query?

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

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
Select Name, City, Country from tableName where Country not like 'USA' or City like 'New York City'

Open in new window

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Why use 'like' when an equality check will do?

'like' is for wildcard use.  It will work but might mess with the optimizer.
Avatar of Arkawa72

ASKER

So if you have the line John, New York City, USA.

Does this line get included because it is in New York or does it get excluded because it in the USA

Sorry for the beginnner-level question. I am pretty new to SQL
yes, the record will be seen in the output
yep, LIKE will be little slower
because the wildcards requires additional processing