Exit Chapter 11 ยท ๐Ÿ” Querying with SQL โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 55 0 correct so far

๐Ÿ” Querying with SQL Quiz

Q1.

Which SQL command is used to fetch (display) data from a table?

Explanation

SELECT retrieves data from one or more tables.

Q2.

What does * mean in SELECT * FROM Student;?

Explanation

* selects every column of the table.

Q3.

Does a SELECT query change the data stored in the table?

Explanation

SELECT only reads data.

Q4.

What is the correct order of clauses in a query?

Explanation

WHERE comes after FROM, and ORDER BY comes last.

Q5.

Which query shows only the Name and Marks columns?

Explanation

Column names are listed after SELECT, separated by commas.

Q6.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE Stream = 'Science';
Explanation

Riya, Zoya and Arjun are in Science.

Q7.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE Marks > 85;
Explanation

Only 92 (Riya) and 88 (Sana) are greater than 85.

Q8.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Fee * 12 FROM Student WHERE Name = 'Kabir';
Explanation

Kabir's fee is 3500, and 3500 ร— 12 = 42000.

Q9.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Marks + 5 FROM Student WHERE Name = 'Meera';
Explanation

Any calculation with NULL gives NULL.

Q10.

Which keyword gives a temporary name (alias) to a column in the output?

Explanation

Example: SELECT Fee * 12 AS AnnualFee FROM Student;

Q11.

An alias with a space in it, like Annual Fee, must be written:

Explanation

Example: AS "Annual Fee".

Q12.

Does a column alias change the column name in the table?

Explanation

An alias is temporary and only for that query's result.

Q13.

Which keyword removes duplicate values from the result?

Explanation

SELECT DISTINCT shows each value only once.

Q14.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT DISTINCT Stream FROM Student;
Explanation

The streams are Science, Commerce and Humanities.

Q15.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT DISTINCT City FROM Student;
Explanation

Kolkata, Delhi, Mumbai, Pune and NULL โ€” DISTINCT keeps one NULL row too.

Q16.

Which clause is used to choose rows that meet a condition?

Explanation

WHERE filters rows.

Q17.

Which operator means 'not equal to' in SQL?

Explanation

SQL uses <> and also accepts !=.

Q18.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE Gender = 'F' AND Stream = 'Science';
Explanation

Riya and Zoya are female Science students.

Q19.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE Stream = 'Science' OR City = 'Delhi';
Explanation

Riya, Zoya, Arjun (Science) and Aman (Delhi).

Q20.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE NOT Stream = 'Commerce';
Explanation

3 rows are Commerce, so 8 โˆ’ 3 = 5.

Q21.

When AND and OR are used together without brackets, which is evaluated first?

Explanation

AND has higher priority than OR; use brackets to be clear.

Q22.

BETWEEN 60 AND 80 includes:

Explanation

BETWEEN includes both end values.

Q23.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE Marks BETWEEN 64 AND 78;
Explanation

78, 64 and 71 are in the range; both ends are included.

Q24.

Which condition is the same as Marks BETWEEN 70 AND 90?

Explanation

BETWEEN is inclusive.

Q25.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE Marks NOT BETWEEN 60 AND 90;
Explanation

Riya (92) and Rohit (55); Meera's NULL is not counted.

Q26.

Which operator matches a column with ANY value from a list?

Explanation

Example: WHERE City IN ('Delhi', 'Pune').

Q27.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE City IN ('Delhi', 'Pune');
Explanation

Aman and Arjun are from Delhi; Meera is from Pune.

Q28.

WHERE City IN ('Delhi', 'Mumbai') is the same as:

Explanation

IN is a short way of writing many OR conditions.

Q29.

Which operator is used for pattern matching?

Explanation

LIKE uses the wildcards % and _.

Q30.

In LIKE, the % wildcard stands for:

Explanation

'A%' matches anything starting with A.

Q31.

In LIKE, the _ (underscore) wildcard stands for:

Explanation

'_a%' means the second letter is a.

Q32.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE Name LIKE 'A%';
Explanation

Names starting with A.

Q33.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE Name LIKE '%a';
Explanation

Names ending with a.

Q34.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE Name LIKE '_a%';
Explanation

The second letter is a in Kabir and Sana.

Q35.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE Name LIKE '____';
Explanation

Names with exactly 4 letters: Riya, Aman, Zoya, Sana.

Q36.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

Which names are displayed by this query?

SELECT Name FROM Student WHERE Name LIKE '%o%';
Explanation

Names containing the letter o anywhere.

Q37.

Which condition correctly finds rows where Marks is NULL?

Explanation

NULL cannot be compared with =; use IS NULL.

Q38.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE Marks = NULL;
Explanation

Comparing with = NULL is never true, so no rows are returned.

Q39.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE City IS NULL;
Explanation

Only Sana's City is NULL.

Q40.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE Marks IS NOT NULL;
Explanation

Only Meera's marks are NULL.

Q41.

Which clause sorts the result of a query?

Explanation

ORDER BY column ASC/DESC sorts the output.

Q42.

What is the default sorting order of ORDER BY?

Explanation

If nothing is written, ORDER BY sorts in ascending order.

Q43.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE Stream = 'Science' ORDER BY Marks DESC;
Explanation

92, 85, 71 in descending order.

Q44.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

What is the output of this query?

SELECT Name FROM Student WHERE Fee = 3500 ORDER BY Name;
Explanation

Names are sorted alphabetically (ASC by default).

Q45.

ORDER BY Stream, Marks DESC will sort the result:

Explanation

With many columns, the second is used only when the first is equal.

Q46.

Which command changes existing values in a table?

Explanation

UPDATE table SET column = value WHERE condition;

Q47.

Which is the correct way to increase every Commerce student's fee by 500?

Explanation

UPDATE ... SET ... WHERE ...;

Q48.

What happens if UPDATE Student SET Fee = 5000; is run WITHOUT a WHERE clause?

Explanation

Without WHERE, UPDATE changes every row.

Q49.

Which command removes rows from a table?

Explanation

DELETE FROM table WHERE condition;

Q50.

What does DELETE FROM Student; (without WHERE) do?

Explanation

The table remains, but it becomes empty.

Q51.

Which is the difference between DELETE and DROP TABLE?

Explanation

DELETE works on data; DROP works on structure.

Q52.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

After running this command, what is Meera's Marks?

UPDATE Student SET Marks = 60 WHERE Marks IS NULL;
Explanation

Meera's Marks was NULL, so it is set to 60.

Q53.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this command delete?

DELETE FROM Student WHERE Stream = 'Humanities';
Explanation

Kabir and Sana are in Humanities.

Q54.

Which query shows the names of students whose City is NOT Kolkata (and City is known)?

Explanation

<> means not equal; rows with NULL City are not shown.

Q55.

Table: Student

RollNo Name Gender Stream Marks Fee City
1 Riya F Science 92 4500 Kolkata
2 Aman M Commerce 78 4000 Delhi
3 Zoya F Science 85 4500 Mumbai
4 Kabir M Humanities 64 3500 Kolkata
5 Meera F Commerce NULL 4000 Pune
6 Arjun M Science 71 4500 Delhi
7 Sana F Humanities 88 3500 NULL
8 Rohit M Commerce 55 4000 Mumbai

How many rows does this query return?

SELECT * FROM Student WHERE City <> 'Kolkata';
Explanation

8 rows minus 2 Kolkata minus 1 NULL City = 5; NULL is not counted.