SQL Questions and Answers – SQL And, Or, Not

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

Answer: b
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

Answer: a
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

Answer: b
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.
advertisement
advertisement

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

Answer: c
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

Answer: a
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

Answer: d
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.

advertisement

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

Answer: d
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.
advertisement

Sanfoundry Global Education & Learning Series – SQL.

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.