MySQL Questions and Answers – Condition Types – 3

This set of MySQL Multiple Choice Questions & Answers (MCQs) focuses on “Condition Types – 3”.

1. Find the error in the following MySQL statement?

SELECT cust_id, fed_id
FROM customer
WHERE cust_id = ’I’
AND fed_id BETWEEN 5000-00-000 AND 9999-999-000;

a) Yes
b) No
c) Range too high to compare
d) None of the mentioned
View Answer

Answer: b
Explanation: In the following query, there will be no error in executing as 5000-00-000 AND 9999-999-000 is “string ranges”.
advertisement
advertisement

2. What will be the output of the following MySQL statement?

SELECT account_id, product_id, cust_id
FROM account
WHERE product_id IN (‘sav’, ‘chd’, ‘mm’);

a) Only those values are selected whose product_id is either ‘sav’, ‘chd’, ‘mm’
b) Only those values are selected whose product_id is either ‘sav’’
c) Only those values are selected whose product_id is either ‘sav’, ‘chd’
d) All of the mentioned
View Answer

Answer: a
Explanation: “IN” operator is used to combine the expressions.
Note: Join free Sanfoundry classes at Telegram or Youtube

3. What will be the output of the following MySQL statement?

advertisement
SELECT account_id, product_id, cust_id
FROM account
WHERE product_id NOT IN (‘sav’, ‘chd’, ‘mm’);

a) Only those values are selected whose product_id does not belong to either ‘sav’, ‘chd’, ‘mm’
b) Only those values are selected whose product_id does not belong to either ‘sav’’
c) Only those values are selected whose product_id does not belong to either ‘sav’, ‘chd’
d) All of the mentioned
View Answer

Answer: a
Explanation: “NOT IN” worked opposite of “IN” operator.
advertisement

4. Consider a database name “Sanfoundry” whose attributes are intern_id (primary key), subject.
Intern_id = {1, 2, 3, 4, 5, 6}
Subject = {sql, oop, sql, oop, c, c++}
If these are one to one relation then what will be the output of the following MySQL statement?

SELECT intern_id
FROM sanfoundry
WHERE subject IN (c, c++);

a) {5, 6}
b) {1, 2, 3}
c) {3, 4}
d) None of the mentioned
View Answer

Answer: a
Explanation: Only those value whose subjects are c and c++.

5. Consider a database name “Sanfoundry” whose attributes are intern_id (primary key), subject.
Intern_id= {1, 2, 3, 4, 5, 6}
Subject= {sql, oop, sql, oop, c, c++}
If these are one to one relation then what will be the output of the following MySQL statement?

SELECT intern_id
FROM sanfoundry
WHERE subject NOT IN (c, c++);

a) {5, 6}
b) {1, 2, 3}
c) {3, 4}
d) None of the mentioned
View Answer

Answer: d
Explanation: Only those value whose subjects are not c and c++ therefore answer is {1, 2, 3, 4}.

6. Consider a database name “Sanfoundry” whose attributes are intern_id (primary key), subject, subject_value.
Intern_id = {1, 2, 3, 4, 5, 6}
Subject = {sql, oop, sql, oop, c, c++}
Subject_value = {0, 0, 1, 1, 2, 2, 3, 3}
If these are one to one relation then what will be the output of the following MySQL statement?

SELECT intern_id
FROM sanfoundry
WHERE subject IN (SELECT subject FROM sanfoundry WHERE subject_value = 3);

a) {5, 6}
b) {1, 2, 3}
c) {3, 4}
d) None of the mentioned
View Answer

Answer: a
Explanation: Only those value will be selected whose subjects are c and c++. In the sub query subject_value=3 which belongs to subject {c, c++} after that this subject belong to intern_id {5, 6).

7. Consider a database name “Sanfoundry” whose attributes are intern_id (primary key), subject, subject_value.
Intern_id = {1, 2, 3, 4, 5, 6}
Subject = {sql, oop, sql, oop, c, c++}
Subject_value = {0, 0, 1, 1, 2, 2, 3, 3}
If these are one to one relation then what will be the output of the following MySQL statement?

SELECT intern_id
FROM sanfoundry
WHERE subject IN (SELECT subject FROM sanfoundry WHERE subject_value IN (3, 2));

a) {5, 6}
b) {1, 2, 3}
c) {3, 4}
d) {1, 2, 3, 4, 5, 6}
View Answer

Answer: d
Explanation: Only those value will be selected whose subjects are c, c++, sql, oop. In the sub query subject_value=3 OR 2 which belongs to subject {c, c++, sql, oop} after that this subject belong to intern_id (1, 2, 3, 4, 5, 6).

8. Consider a database name “Sanfoundry” whose attributes are intern_id (primary key), subject.
Intern_id = {1, 2, 3, 4, 5, 6}
Subject = {sql, oop, sql, oop, c, c++}
If these are one to one relation then what will be the output of the following MySQL statement?

SELECT intern_id
FROM sanfoundry
WHERE subject NOT IN (c, c++, oop);

a) {5, 6}
b) {1, 2, 3}
c) {3, 4}
d) {1, 4}
View Answer

Answer: d
Explanation: Only those value whose subjects are not {c, c++, oop} therefore answer is {1, 4}.

9. Consider a database name “Sanfoundry” whose attributes are intern_id (primary key), subject.
Intern_id = {1, 2, 3, 4, 5, 6}
Subject = {sql, oop, sql, oop, c, c++}
If these are one to one relation then what will be the output of the following MySQL statement?

SELECT intern_id
FROM sanfoundry
WHERE subject IN (c, c++, oop);

a) {5, 6}
b) {1, 2, 3}
c) {3, 4}
d) {2, 4, 5, 6}
View Answer

Answer: d
Explanation: Only those value whose subjects are {c, c++, oop} therefore answer is {2, 4, 5, 6}.

10. Consider a database name “Sanfoundry” whose attributes are intern_id (primary key), subject.
Intern_id = {1, 2, 3, 4, 5, 6}
Subject = {sql, oop, sql, oop, c, c++}
If these are one to one relation then what will be the output of the following MySQL statement?

SELECT intern_id
FROM sanfoundry
WHERE subject IN (c, c++, oop, SQL);

a) {5, 6}
b) {1, 2, 3}
c) {3, 4}
d) Empty set
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice all areas of MySQL Database, 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.