Examveda

Consider a database name "db_name" 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 db_name
WHERE subject NOT IN (c, c++, oop);

A. {5, 6}

B. {1, 2, 3}

C. {3, 4}

D. {1, 4}

Answer: Option D

Solution (By Examveda Team)

This question is about understanding how to use the "NOT IN" operator in MySQL to filter data. Let's break down what's happening:
* The Database: We have a database named "db_name" that stores information about interns. Each intern has a unique "intern_id" and a "subject" they are studying.
* The Data: * "intern_id" values are: 1, 2, 3, 4, 5, 6 * "subject" values are: sql, oop, sql, oop, c, c++
* One-to-One Relation: This means that each intern is associated with exactly one subject, and each subject is associated with exactly one intern.
* The SQL Statement:
```sql SELECT intern_id FROM db_name WHERE subject NOT IN (c, c++, oop); ```
This statement is asking us to:
1. SELECT the "intern_id" column.
2. FROM the database "db_name".
3. WHERE the "subject" column "NOT IN" the list of values: "c", "c++", or "oop".
* Finding the Answer:
Let's examine the data to see which "intern_id" values have subjects that are "NOT IN" the specified list:
* Intern 1: "subject" is "sql" - NOT in the list.
* Intern 2: "subject" is "oop" - IN the list (not selected).
* Intern 3: "subject" is "sql" - NOT in the list.
* Intern 4: "subject" is "oop" - IN the list (not selected).
* Intern 5: "subject" is "c" - IN the list (not selected).
* Intern 6: "subject" is "c++" - IN the list (not selected).
* Therefore, the correct answer is:
Option B: {1, 2, 3}
This is because the "intern_id" values 1 and 3 have subjects that are not "c", "c++", or "oop".

This Question Belongs to MySQL >> MySQL Miscellaneous

Join The Discussion

Related Questions on MySQL Miscellaneous