Showing 11–19 of 19 questions
Which SQL JOIN returns only matching rows from both tables?
A
LEFT JOIN
B
RIGHT JOIN
C
INNER JOIN
D
FULL OUTER JOIN
Correct Answer:
C. INNER JOIN
Explanation:
INNER JOIN returns only rows where join condition is satisfied in both tables. Other JOINs include non-matching rows.
What will be the result of: SELECT 10 % 3; in SQL?
Explanation:
The modulus operator (%) returns remainder after division. 10 divided by 3 gives remainder 1.
What is the result of: SELECT CASE WHEN 1=1 THEN 'A' WHEN 2=2 THEN 'B' ELSE 'C' END;?
Explanation:
CASE statement evaluates conditions sequentially and returns value for first TRUE condition. 1=1 is TRUE, so 'A' is returned.
Which SQL command is used to remove all records from a table without removing the table structure?
A
DELETE
B
TRUNCATE
C
DROP
D
REMOVE
Correct Answer:
B. TRUNCATE
Explanation:
TRUNCATE removes all rows but keeps the table structure. DELETE removes rows one by one and can be rolled back. DROP removes the entire table.
In a student enrollment database, you need to find students enrolled in multiple courses. Which JOIN type should be used to match course_id from enrollment table with course table?
A
INNER JOIN
B
LEFT JOIN
C
RIGHT JOIN
D
CROSS JOIN
Correct Answer:
A. INNER JOIN
Explanation:
INNER JOIN returns only matching records from both tables, perfect for finding students with matching course enrollments.
What is the default sort order for ORDER BY clause in SQL?
A
Ascending
B
Descending
C
Random
D
Alphabetical
Correct Answer:
A. Ascending
Explanation:
ORDER BY sorts in ascending order by default. Use DESC keyword for descending order.
Which aggregate function ignores NULL values in SQL?
A
COUNT(*)
B
COUNT(column_name)
C
SUM()
D
Both B and C
Correct Answer:
D. Both B and C
Explanation:
COUNT(column_name), SUM(), AVG(), MAX(), and MIN() all ignore NULL values. COUNT(*) counts all rows including NULLs.
Which SQL statement is used to add a new column to existing table?
A
ADD COLUMN
B
ALTER TABLE ... ADD
C
INSERT COLUMN
D
UPDATE TABLE ... ADD
Correct Answer:
B. ALTER TABLE ... ADD
Explanation:
ALTER TABLE ... ADD COLUMN syntax is correct for adding columns. Other options are invalid SQL syntax.
Which feature of SQL allows preventing duplicate values in a column?
A
PRIMARY KEY constraint
B
UNIQUE constraint
C
NOT NULL constraint
D
FOREIGN KEY constraint
Correct Answer:
B. UNIQUE constraint
Explanation:
UNIQUE constraint prevents duplicate values. PRIMARY KEY is unique + NOT NULL. NOT NULL only prevents nulls. FOREIGN KEY maintains referential integrity.