Introduction to SQL

Q1: Find the SQL statement below that is equal to the following: SELECT NAME FROM CUSTOMER WHERE STATE = 'VA';

A SELECT NAME IN CUSTOMER WHERE STATE IN ('VA');

B SELECT NAME IN CUSTOMER WHERE STATE = 'VA';

C SELECT NAME IN CUSTOMER WHERE STATE = 'V';

D SELECT NAME FROM CUSTOMER WHERE STATE IN ('VA');

ANS:D - SELECT NAME FROM CUSTOMER WHERE STATE IN ('VA');

The IN function helps reduce the need to use multiple OR conditions.

The syntax for the IN function is:

SELECT columns
FROM tables
WHERE column1 in (value1, value2, .... value_n);

This SQL statement will return the records where column1 is value1, value2..., or value_n. The IN function can be used in any valid SQL statement - select, insert, update, or delete.
Example #1:

The following is an SQL statement that uses the IN function:

SELECT *
FROM suppliers
WHERE supplier_name in ( 'IBM', 'Hewlett Packard', 'Microsoft');

This would return all rows where the supplier_name is either IBM, Hewlett Packard, or Microsoft. Because the * is used in the select, all fields from the suppliers table would appear in the result set.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.