1/49
Flashcards for SQL DML MCQs
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
SELECT
Retrieve data
What clause must follow the SELECT clause?
FROM
SELECT * FROM employees;
Selects all columns
DISTINCT keyword
Returns only unique values
Which keyword assigns an alias to a column?
AS
Which keyword is optional but recommended when using aliases?
AS
Which clause restricts the rows returned in a query?
WHERE
Which comparison operator means 'not equal'?
<> and !=
WHERE first_name LIKE 'S%'
First names that start with 'S'
Which character is used in LIKE to represent a single character?
_
What does IN check for?
A value in a list
What will IS NULL return?
All rows with NULL in the column
Which operator checks if a value lies within a specific range?
BETWEEN
Which of the following is a valid logical operator?
NOT, OR, AND
What is the result of AND if both conditions are TRUE?
TRUE
What does NOT do?
Reverses the condition
What is the first order of precedence in SQL evaluation?
Comparison operators
How can you override precedence in SQL?
Use parentheses
What is the default order for ORDER BY?
Ascending
Which clause is used to sort rows in SQL?
ORDER BY
Which symbol is used for multiplication in SQL?
*
Which has higher precedence: addition or multiplication?
Multiplication
Which operator is used to concatenate strings?
||
Which query shows full employee name and department number?
SELECT firstname || ' ' || lastname || ' works in department ' || department_id FROM employees;
SELECT table1.column1, table2.column2 FROM table1, table2 WHERE table1.id = table2.id;
Joins two tables
What is a table alias?
A temporary table name
Which JOIN returns only matched records from both tables?
INNER JOIN
Which JOIN returns all records from the left table?
LEFT JOIN
Which JOIN gives a Cartesian product?
CROSS JOIN
What is the result of FULL OUTER JOIN?
All matched and unmatched rows
Which statement adds new rows?
INSERT
What happens if you insert a row with a foreign key that doesn't exist?
Error
What is the correct syntax for inserting values?
INSERT INTO table (columns) VALUES (values);
What clause is optional in UPDATE but critical to target specific rows?
WHERE
What happens if you omit WHERE in UPDATE?
All rows updated
How do you delete all rows from a table?
DELETE FROM table;
What command can undo a DELETE (if not committed)?
ROLLBACK
What happens when a DELETE has no WHERE clause?
All rows deleted
What must you do before inserting a new department with a new location?
Insert into locations table first
How do you correct a wrongly inserted department name?
UPDATE
What does a SELF JOIN do?
Joins a table to itself
What does the CROSS JOIN result in?
Cartesian product
Which join displays customers even if they haven't placed orders?
LEFT JOIN
What is the purpose of using AS in a JOIN?
Assign aliases
SELECT A.name, B.name FROM A, B WHERE A.city = B.city, what type of join is this?
Equi-Join
Which command saves all changes made in a session?
COMMIT
What is needed to avoid invalid foreign key entries?
Existing referenced records
SELECT * FROM employees WHERE salary BETWEEN 3000 AND 6000;
Shows salaries from 3000 to 6000
What type of JOIN will always show nulls for unmatched rows on both sides?
FULL OUTER
What command permanently removes a table?
DROP