Playing as a guest? to earn XP and track your progress.
๐ Querying with SQL Quiz
๐ Querying with SQL
Which SQL command is used to fetch (display) data from a table?
DISPLAY
SELECT
FETCH
SHOW
SELECT retrieves data from one or more tables.
What does * mean in SELECT * FROM Student;?
All rows with NULL
All columns
The first column
Multiply
* selects every column of the table.
Does a SELECT query change the data stored in the table?
Only with ORDER BY
Yes, it deletes NULL values
Yes, it sorts the table permanently
No, it only displays data
SELECT only reads data.
What is the correct order of clauses in a query?
SELECT โฆ FROM โฆ WHERE โฆ ORDER BY โฆ
SELECT โฆ WHERE โฆ FROM โฆ ORDER BY โฆ
FROM โฆ SELECT โฆ ORDER BY โฆ WHERE โฆ
SELECT โฆ ORDER BY โฆ WHERE โฆ FROM โฆ
WHERE comes after FROM, and ORDER BY comes last.
Which query shows only the Name and Marks columns?
SELECT Name AND Marks FROM Student;
SELECT * Name, Marks FROM Student;
SELECT Name, Marks FROM Student;
SELECT FROM Student Name, Marks;
Column names are listed after SELECT, separated by commas.
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';8
2
3
4
Riya, Zoya and Arjun are in Science.
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;Riya, Sana
Zoya, Sana
Riya, Zoya, Sana
Riya
Only 92 (Riya) and 88 (Sana) are greater than 85.
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';3512
NULL
3500
42000
Kabir's fee is 3500, and 3500 ร 12 = 42000.
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';Error
0
5
NULL
Any calculation with NULL gives NULL.
Which keyword gives a temporary name (alias) to a column in the output?
ALIAS
RENAME
AS
NAME
Example: SELECT Fee * 12 AS AnnualFee FROM Student;
An alias with a space in it, like Annual Fee, must be written:
Inside quotes
With an underscore only
In capital letters
It is not allowed
Example: AS "Annual Fee".
Does a column alias change the column name in the table?
Only for numbers
Yes, permanently
Only with ORDER BY
No, it only changes the heading in the output
An alias is temporary and only for that query's result.
Which keyword removes duplicate values from the result?
DISTINCT
DIFFERENT
UNIQUE
SINGLE
SELECT DISTINCT shows each value only once.
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;3
8
4
2
The streams are Science, Commerce and Humanities.
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;5
8
4
6
Kolkata, Delhi, Mumbai, Pune and NULL โ DISTINCT keeps one NULL row too.
Which clause is used to choose rows that meet a condition?
WHERE
ORDER BY
DISTINCT
FROM
WHERE filters rows.
Which operator means 'not equal to' in SQL?
=!
==
<> (or !=)
<
SQL uses <> and also accepts !=.
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';2
4
6
3
Riya and Zoya are female Science students.
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';3
5
4
2
Riya, Zoya, Arjun (Science) and Aman (Delhi).
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';3
5
8
6
3 rows are Commerce, so 8 โ 3 = 5.
When AND and OR are used together without brackets, which is evaluated first?
OR
Whichever comes first
AND
Neither โ it gives an error
AND has higher priority than OR; use brackets to be clear.
BETWEEN 60 AND 80 includes:
Only 80
Only 60
Neither 60 nor 80
Both 60 and 80
BETWEEN includes both end values.
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;Aman, Kabir, Arjun, Rohit
Aman, Arjun
Kabir, Arjun
Aman, Kabir, Arjun
78, 64 and 71 are in the range; both ends are included.
Which condition is the same as Marks BETWEEN 70 AND 90?
Marks >= 70 OR Marks <= 90
Marks = 70 AND Marks = 90
Marks >= 70 AND Marks <= 90
Marks > 70 AND Marks < 90
BETWEEN is inclusive.
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;3
1
2
4
Riya (92) and Rohit (55); Meera's NULL is not counted.
Which operator matches a column with ANY value from a list?
IN
LIKE
ANY
BETWEEN
Example: WHERE City IN ('Delhi', 'Pune').
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');Meera
Aman, Meera, Arjun
Aman, Meera
Aman, Arjun
Aman and Arjun are from Delhi; Meera is from Pune.
WHERE City IN ('Delhi', 'Mumbai') is the same as:
WHERE City BETWEEN 'Delhi' AND 'Mumbai'
WHERE City = 'Delhi' OR City = 'Mumbai'
WHERE City = 'Delhi' AND City = 'Mumbai'
WHERE City LIKE 'Delhi, Mumbai'
IN is a short way of writing many OR conditions.
Which operator is used for pattern matching?
IN
MATCH
BETWEEN
LIKE
LIKE uses the wildcards % and _.
In LIKE, the % wildcard stands for:
Exactly one character
Only digits
A percentage
Any number of characters (including none)
'A%' matches anything starting with A.
In LIKE, the _ (underscore) wildcard stands for:
Exactly one character
No character
Any number of characters
A space
'_a%' means the second letter is a.
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%';Aman, Arjun
Aman, Arjun, Sana
Arjun
Aman
Names starting with A.
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';Aman, Sana
Riya, Zoya
Riya, Zoya, Meera, Sana
Meera, Sana
Names ending with a.
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%';Aman, Arjun
Kabir, Sana
Sana
Kabir, Sana, Aman
The second letter is a in Kabir and Sana.
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 '____';8
3
4
5
Names with exactly 4 letters: Riya, Aman, Zoya, Sana.
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%';Zoya, Rohit, Kabir
Zoya, Rohit
Zoya
Rohit
Names containing the letter o anywhere.
Which condition correctly finds rows where Marks is NULL?
WHERE Marks == NULL
WHERE Marks = NULL
WHERE Marks IS NULL
WHERE Marks = 'NULL'
NULL cannot be compared with =; use IS NULL.
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;8
1
0
Error
Comparing with = NULL is never true, so no rows are returned.
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;Sana
Sana, Meera
No rows
Meera
Only Sana's City is NULL.
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;8
1
7
6
Only Meera's marks are NULL.
Which clause sorts the result of a query?
ARRANGE BY
ORDER BY
SORT BY
GROUP BY
ORDER BY column ASC/DESC sorts the output.
What is the default sorting order of ORDER BY?
Random
Order of insertion
Ascending (ASC)
Descending (DESC)
If nothing is written, ORDER BY sorts in ascending order.
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;Riya, Arjun, Zoya
Riya, Zoya, Arjun
Arjun, Zoya, Riya
Zoya, Riya, Arjun
92, 85, 71 in descending order.
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;Kabir, Sana
Sana
Kabir
Sana, Kabir
Names are sorted alphabetically (ASC by default).
ORDER BY Stream, Marks DESC will sort the result:
By Stream first, and by Marks (high to low) within the same Stream
Randomly
By Marks only
By Stream descending and Marks ascending
With many columns, the second is used only when the first is equal.
Which command changes existing values in a table?
UPDATE
INSERT
MODIFY
ALTER
UPDATE table SET column = value WHERE condition;
Which is the correct way to increase every Commerce student's fee by 500?
UPDATE Student Fee = Fee + 500 WHERE Stream = 'Commerce';
UPDATE Student SET Fee = Fee + 500 WHERE Stream = 'Commerce';
UPDATE Fee + 500 IN Student;
ALTER Student SET Fee = Fee + 500;
UPDATE ... SET ... WHERE ...;
What happens if UPDATE Student SET Fee = 5000; is run WITHOUT a WHERE clause?
Only the first row changes
The Fee of ALL rows becomes 5000
An error occurs
Nothing changes
Without WHERE, UPDATE changes every row.
Which command removes rows from a table?
REMOVE
DELETE
DROP
ALTER
DELETE FROM table WHERE condition;
What does DELETE FROM Student; (without WHERE) do?
Removes all rows but keeps the table
Deletes only the first row
Deletes the whole table structure
Gives an error
The table remains, but it becomes empty.
Which is the difference between DELETE and DROP TABLE?
There is no difference
DROP removes rows; DELETE removes the table
DELETE removes rows (DML); DROP TABLE removes the whole table (DDL)
Both remove only rows
DELETE works on data; DROP works on structure.
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;60
NULL
Error
0
Meera's Marks was NULL, so it is set to 60.
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';1
2
3
8
Kabir and Sana are in Humanities.
Which query shows the names of students whose City is NOT Kolkata (and City is known)?
SELECT Name FROM Student WHERE City <> 'Kolkata';
SELECT Name FROM Student WHERE NOT City;
SELECT Name FROM Student WHERE City = NOT 'Kolkata';
SELECT Name FROM Student WHERE City != NULL;
<> means not equal; rows with NULL City are not shown.
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';6
7
4
5
8 rows minus 2 Kolkata minus 1 NULL City = 5; NULL is not counted.