How do you select rows where country is one of 'USA', 'Canada', or 'UK'?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

How do you select rows where country is one of 'USA', 'Canada', or 'UK'?

Explanation:
Using the IN operator lets you filter a column to a set of allowed values by listing them in parentheses after IN. For string values, each item must be a quoted string literal. This provides a concise way to express multiple possibilities without writing multiple OR conditions. In this case, you want the country to be one of 'USA', 'Canada', or 'UK', so the correct query is: SELECT * FROM customers WHERE country IN ('USA','Canada','UK'); This returns rows where the country matches any of those three values. Why this approach is preferred: it’s cleaner and easier to extend if you need to add more countries later. The other forms fail for reasons like missing one country, omitting quotes around string literals, or having a syntax error from an extra quote, so they won’t reliably select the intended rows.

Using the IN operator lets you filter a column to a set of allowed values by listing them in parentheses after IN. For string values, each item must be a quoted string literal. This provides a concise way to express multiple possibilities without writing multiple OR conditions.

In this case, you want the country to be one of 'USA', 'Canada', or 'UK', so the correct query is: SELECT * FROM customers WHERE country IN ('USA','Canada','UK'); This returns rows where the country matches any of those three values.

Why this approach is preferred: it’s cleaner and easier to extend if you need to add more countries later.

The other forms fail for reasons like missing one country, omitting quotes around string literals, or having a syntax error from an extra quote, so they won’t reliably select the intended rows.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy