We help IT Professionals succeed at work.

Sql select query

Arkawa72
Arkawa72 asked
on
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?

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
Unless I'm missing something it is a simple 'or':

select * from table where country != 'USA' or city='New York City';
Select Name, City, Country from tableName where Country not like 'USA' or City like 'New York City'

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019

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

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

Author

Commented:
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

Explore More ContentExplore courses, solutions, and other research materials related to this topic.