This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL And, Or, Not”.
1. The AND operator displays a record if ____________
a) Any of the conditions separated by AND is true
b) All the conditions separated by AND is true
c) Any of the conditions separated by AND is not true
d) All the conditions separated by AND is not true
View Answer
Explanation: The WHERE clause can be combined with AND operator. AND operator is used to filter rows when more than one condition has to be checked. It displays a record if all the conditions separated by AND is TRUE.
2. The OR operator displays a record if ________
a) Any of the conditions separated by OR is true
b) All the conditions separated by OR is true
c) Any of the conditions separated by OR is not true
d) All the conditions separated by OR is not true
View Answer
Explanation: The WHERE clause can be combined with OR operator. This OR operator is used to filter records when more than one condition is given. It displays a record if any of the conditions separated by OR is TRUE.
3. The NOT operator displays a record if the condition(s) is NOT FALSE.
a) True
b) False
View Answer
Explanation: The WHERE clause can be combined with NOT operator. The NOT operator displays a record if the condition(s) is NOT TRUE. It doesn’t display a record if the condition(s) is TRUE.
4. What is the basic AND syntax?
a) Select * from table_name where condition1 && condition2;
b) Select * from table_name where condition1 & condition2;
c) Select *from table_name where condition1 AND condition2;
d) Select *from table_name where condition1 AND & condition2;
View Answer
Explanation: AND, OR is used to filter records based on more than one condition. &, &&, AND & are not valid operators in SQL. So, they cannot be used with WHERE clause.
5. Which of the following is the correct syntax to use OR operator?
a) Select * from table_name where condition1 OR condition2;
b) Select * from table_name where condition1 || condition2;
c) Select *from table_name where condition1 |condition2;
d) Select *from table_name where condition1 OR | condition2;
View Answer
Explanation: AND, OR is used to filter records based on more than one condition. |, ||, OR | are not valid operators in SQL. So, they cannot be used with WHERE clause.
6. With SQL, how do you select all fields from “Customers” table whose country is NOT “Germany” and NOT “USA”?
a) Select * from Customers where not country=’Germany’ and country=’USA’;
b) Select * from Customers where not country=’USA’ and country=’Germany’;
c) Select * from Customers where not(country=’USA’ and country=’Germany’);
d) Select * from Customers where not(country=’USA’ or country=’Germany’);
View Answer
Explanation:
SELECT * FROM Customers WHERE NOT (country=’USA’ OR country=’Germany’);
This query selects all columns from given table that doesn’t belong to Germany and USA, whereas the rest of the queries retrieve some other records.
7. When three or more AND and OR conditions are combined, which keyword is used to replace the query simple?
a) Like
b) Between
c) AND OR
d) In
View Answer
Explanation: The IN operator allows us to specify multiple values in a WHERE clause. It is used to replace when three or more AND and OR conditions are combined, to make the SQL query simple.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.