Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
SQL is used to create, retrieve, update, and manage data in relational databases.
Question 2 of 60 · DDL commands · Easy
Which SQL command creates a new table?
Not quite. Try another option.
Answer: CREATE
The CREATE command defines a new database object, such as a table.
Question 3 of 60 · DDL commands · Easy
Which DDL command changes the structure of an existing table?
Not quite. Try another option.
Answer: ALTER
The ALTER command adds, removes, or modifies columns and constraints in a table.
Question 4 of 60 · DML commands · Easy
Which SQL command adds a new row to a table?
Not quite. Try another option.
Answer: INSERT
The INSERT command adds one or more new rows to a table.
Question 5 of 60 · DML commands · Easy
Which SQL command changes existing data in a table?
Not quite. Try another option.
Answer: UPDATE
The UPDATE command modifies values in existing rows.
Question 6 of 60 · DCL commands · Easy
Which DCL command gives a user database privileges?
Not quite. Try another option.
Answer: GRANT
The GRANT command gives specified database permissions to a user or role.
Question 7 of 60 · TCL commands · Easy
Which TCL command permanently saves the changes made in a transaction?
Not quite. Try another option.
Answer: COMMIT
The COMMIT command permanently saves the changes made during the current transaction.
Question 8 of 60 · Keys and their types · Easy
Which key uniquely identifies each row in a table?
Not quite. Try another option.
Answer: Primary key
A primary key contains unique, non-null values that identify individual rows.
Question 9 of 60 · Keys and their types · Easy
Which key creates a relationship by referring to a key in another table?
Not quite. Try another option.
Answer: Foreign key
A foreign key refers to a primary or unique key in another table.
Question 10 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Easy
Which aggregate function returns the smallest value in a column?
Not quite. Try another option.
Answer: MIN()
The MIN() function returns the lowest value found in the selected column.
Question 11 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Easy
Which aggregate function calculates the arithmetic mean of numeric values?
Not quite. Try another option.
Answer: AVG()
The AVG() function calculates the arithmetic mean of the non-null numeric values.
Question 12 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Easy
Which aggregate function returns the number of rows matched by a query?
Not quite. Try another option.
Answer: COUNT()
The COUNT() function counts rows or non-null values, depending on its argument.
Question 13 of 60 · Self join · Easy
What does a self join do?
Not quite. Try another option.
Answer: Joins a table with itself
A self join treats one table as two aliases and matches rows within that table.
Question 14 of 60 · Equi join · Easy
Which operator is used in the matching condition of an equi join?
Not quite. Try another option.
Answer: =
An equi join matches rows by testing whether selected column values are equal.
Question 15 of 60 · Inner join · Easy
Which rows are returned by an inner join?
Not quite. Try another option.
Answer: Rows matching in both tables
An inner join returns rows that satisfy the join condition in both tables.
Question 16 of 60 · Outer join · Easy
What does a left outer join return?
Not quite. Try another option.
Answer: All left rows and matching right rows
A left outer join keeps every row from the left table and adds matching right-table data.
Question 17 of 60 · Cross join · Easy
What result does a cross join produce?
Not quite. Try another option.
Answer: Every combination of table rows
A cross join produces the Cartesian product of the rows in the joined tables.
Question 18 of 60 · GROUP BY clause · Easy
What is the main purpose of the GROUP BY clause?
Not quite. Try another option.
Answer: To arrange rows into groups
GROUP BY collects rows with common values so aggregate functions can be applied to each group.
Question 19 of 60 · HAVING clause · Easy
Which clause filters groups after a GROUP BY operation?
Not quite. Try another option.
Answer: HAVING
The HAVING clause applies conditions to groups, often using aggregate results.
Question 20 of 60 · ORDER BY clause · Easy
Which clause sorts the rows in a query result?
Not quite. Try another option.
Answer: ORDER BY
The ORDER BY clause sorts query results in ascending or descending order.
Question 21 of 60 · Introduction to SQL · Medium
A developer writes SELECT name FROM Student WHERE marks >= 75; without specifying how records should be scanned. Which SQL characteristic does this demonstrate?
Not quite. Try another option.
Answer: SQL is a declarative language
SQL specifies the required result, while the database system determines how to retrieve it.
Question 22 of 60 · DDL commands · Medium
A populated Employee table needs a new email column without removing its existing rows. Which command is most appropriate?
Not quite. Try another option.
Answer: ALTER TABLE Employee ADD email VARCHAR(100);
ALTER TABLE changes an existing table's structure while retaining its current records.
Question 23 of 60 · DDL commands · Medium
Which statement removes both the TemporaryData table definition and all rows stored in it?
Not quite. Try another option.
Answer: DROP TABLE TemporaryData;
DROP TABLE removes the table object, including its structure and stored data.
Question 24 of 60 · DML commands · Medium
The salary of every employee in department 4 must increase by 10%. Which statement performs the required change?
Not quite. Try another option.
Answer: UPDATE Employee SET salary = salary * 1.10 WHERE dept_id = 4;
UPDATE modifies existing rows, and multiplication by 1.10 applies a 10% increase.
Question 25 of 60 · DCL commands · Medium
User reporter should be allowed to read the Sales table but not modify it. Which command provides the required privilege?
Not quite. Try another option.
Answer: GRANT SELECT ON Sales TO reporter;
GRANT SELECT gives the user permission to query the table without granting modification rights.
Question 26 of 60 · TCL commands · Medium
A transaction creates savepoint before_update, performs two valid inserts, and then performs an incorrect update. Which command undoes only the work after that savepoint?
Not quite. Try another option.
Answer: ROLLBACK TO before_update;
ROLLBACK TO reverses changes made after the specified savepoint without canceling the entire transaction.
Question 27 of 60 · Keys and their types · Medium
In Enrollment(student_id, course_id, semester), a student may take many courses and a course may have many students. Each student can enroll in a course only once per semester. Which primary key best enforces this rule?
Not quite. Try another option.
Answer: (student_id, course_id, semester)
All three columns are required to uniquely identify one student's enrollment in one course during one semester.
Question 28 of 60 · Keys and their types · Medium
The column Order.customer_id references Customer.customer_id. What type of key is Order.customer_id in the Order table?
Not quite. Try another option.
Answer: Foreign key
A foreign key references a key in another table and helps maintain referential integrity.
Question 29 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Medium
A department has salary values 40000, 50000, and NULL. What does AVG(salary) return for that department?
Not quite. Try another option.
Answer: 45000
AVG ignores NULL values, so the result is .
Question 30 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Medium
Which query returns the lowest and highest product prices in a single result row?
Not quite. Try another option.
Answer: SELECT MIN(price), MAX(price) FROM Product;
MIN returns the lowest value, while MAX returns the highest value.
Question 31 of 60 · Self join · Medium
Table Employee(emp_id, name, manager_id) stores each manager's ID in the same table. Which query correctly lists each employee with the employee's manager?
Not quite. Try another option.
Answer: SELECT e.name, m.name FROM Employee e JOIN Employee m ON e.manager_id = m.emp_id;
A self join uses two aliases for the same table and matches an employee's manager_id to the manager's emp_id.
Question 32 of 60 · Equi join · Medium
Which condition makes a join between Orders and Customer an equi join?
Not quite. Try another option.
Answer: Orders.customer_id = Customer.customer_id
An equi join matches rows by using the equality operator on related columns.
Question 33 of 60 · Inner join · Medium
A query must return only customers who have at least one matching order. Which join should be used between Customer and Orders?
Not quite. Try another option.
Answer: INNER JOIN
An inner join returns only rows having matching values in both joined tables.
Question 34 of 60 · Outer join · Medium
A report must list every customer, including customers who have placed no orders. Which query meets this requirement?
Not quite. Try another option.
Answer: SELECT * FROM Customer c LEFT JOIN Orders o ON c.id = o.customer_id;
A left join preserves every row from Customer and supplies NULL values when no order matches.
Question 35 of 60 · Cross join · Medium
Table Size contains 6 rows and table Color contains 4 rows. How many rows are produced by Size CROSS JOIN Color?
Not quite. Try another option.
Answer: rows
A cross join produces every possible pair, giving rows.
Question 36 of 60 · GROUP BY clause · Medium
Which query correctly returns the number of employees in each department?
Not quite. Try another option.
Answer: SELECT dept_id, COUNT(*) FROM Employee GROUP BY dept_id;
GROUP BY dept_id forms one group per department so COUNT(*) can count its employees.
Question 37 of 60 · HAVING clause · Medium
Which query returns only departments whose average salary is greater than 60000?
Not quite. Try another option.
Answer: SELECT dept_id FROM Employee GROUP BY dept_id HAVING AVG(salary) > 60000;
HAVING filters groups after aggregation, so it is appropriate for a condition on AVG(salary).
Question 38 of 60 · ORDER BY clause · Medium
A product list must be sorted from highest to lowest price, with equal-priced products sorted alphabetically by name. Which clause is correct?
Not quite. Try another option.
Answer: ORDER BY price DESC, name ASC
The first expression sorts prices descending, and the second breaks price ties by name ascending.
Question 39 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Medium
A table contains 5 rows, but bonus is NULL in 2 of them. What values are returned by COUNT(*) and COUNT(bonus)?
Not quite. Try another option.
Answer: 5 and 3
COUNT(*) counts all rows, whereas COUNT(bonus) counts only rows where bonus is not NULL.
Question 40 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Medium
Which query calculates total sales for each region and retains only regions whose total exceeds 100000?
Not quite. Try another option.
Answer: SELECT region, SUM(amount) FROM Sales GROUP BY region HAVING SUM(amount) > 100000;
SUM calculates each regional total, and HAVING filters the resulting groups by that aggregate.
Question 41 of 60 · Introduction to SQL · Hard
Table T(x) contains the rows 1, 2, and NULL. Under standard SQL three-valued logic, which values are returned by SELECT x FROM T WHERE NOT (x = 1);?
Not quite. Try another option.
Answer: Only 2
For NULL, the comparison x = 1 is UNKNOWN, and NOT UNKNOWN remains UNKNOWN. A WHERE clause retains only TRUE rows.
Question 42 of 60 · DDL commands · Hard
Table Child has a foreign key referencing Parent(id). What happens under standard SQL when DROP TABLE Parent RESTRICT; is executed while that foreign key exists?
Not quite. Try another option.
Answer: It fails because the foreign key is a dependent object.
RESTRICT prevents the table from being dropped while dependent objects, such as referencing foreign keys, still exist.
Question 43 of 60 · DML commands · Hard
Before the following statement, department A has salaries 100, 200, 300, and department B has salaries 50, 150. What is the total salary afterward?
UPDATE Employee AS e SET salary = salary + 10 WHERE salary < (SELECT AVG(e2.salary) FROM Employee AS e2 WHERE e2.dept = e.dept);
Not quite. Try another option.
Answer: 820
The original departmental averages are 200 and 100. Salaries 100 and 50 are increased, raising the original total of 800 by 20.
Question 44 of 60 · DCL commands · Hard
Alice grants SELECT on R to Bob with the grant option, and Bob grants it to Carol. Alice then executes REVOKE GRANT OPTION FOR SELECT ON R FROM Bob CASCADE;. What is the resulting access?
Not quite. Try another option.
Answer: Bob retains SELECT; Carol loses SELECT.
Revoking only the grant option leaves Bob's own privilege intact. CASCADE removes Carol's privilege because it depends on Bob's former grant authority.
Question 45 of 60 · TCL commands · Hard
Accounts A and B initially contain 500 each. A transaction executes: subtract 100 from A; create savepoint S; add 100 to B; ROLLBACK TO S; then COMMIT. What balances are committed?
Not quite. Try another option.
Answer: A = 400, B = 500
Rollback to S reverses only work performed after the savepoint. The debit occurred before S, so it is committed while the credit is undone.
Question 46 of 60 · Keys and their types · Hard
For relation R(A, B, C, D), the functional dependencies are , , and . Which set lists all candidate keys?
Not quite. Try another option.
Answer: {A, C} and {B, C}
Either A or B determines the other, but C cannot be derived and is required. Both {A,C} and {B,C} determine every attribute and are minimal.
Question 47 of 60 · Keys and their types · Hard
Department has primary key dept_id and a UNIQUE NOT NULL column dept_code. Employee.dept_code is nullable. Which constraint declaration is valid under standard relational key rules?
Not quite. Try another option.
Answer: Employee.dept_code may reference Department.dept_code.
A foreign key may reference a declared candidate key, including a UNIQUE NOT NULL alternate key. A nullable foreign-key value can also remain NULL.
Question 48 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Hard
Column v contains 10, NULL, 20, and 30. What tuple is produced by SELECT COUNT(*), COUNT(v), SUM(v), AVG(v), MIN(v), MAX(v) FROM T;?
Not quite. Try another option.
Answer: (4, 3, 60, 20, 10, 30)
COUNT(*) counts every row. The other aggregates ignore NULL, so three values contribute to the sum, average, minimum, and maximum.
Question 49 of 60 · Aggregate functions: MIN, MAX, SUM, AVG and COUNT · Hard
Customer A has two matching orders, while customer B has none. For each customer, a query computes COUNT(*) and COUNT(o.order_id) after a LEFT JOIN to Orders o. What pairs are returned for A and B?
Not quite. Try another option.
Answer: A: (2, 2), B: (1, 0)
The outer join creates one null-extended row for B. COUNT(*) counts it, whereas COUNT(o.order_id) ignores its NULL order identifier.
Question 50 of 60 · Self join · Hard
Table Employee(id, manager_id) stores a hierarchy. Which query finds employees whose manager's manager has id = 1?
Not quite. Try another option.
Answer: SELECT e.id FROM Employee e JOIN Employee m ON e.manager_id = m.id JOIN Employee g ON m.manager_id = g.id WHERE g.id = 1;
Alias m represents the employee's manager, and alias g represents that manager's manager. The two joins follow the hierarchy upward twice.
Question 51 of 60 · Equi join · Hard
Table A contains join-key values 1, 1, 2, and table B contains 1, 1, 1, 3. How many rows result from A JOIN B ON A.key = B.key?
Not quite. Try another option.
Answer: 6
Each of the two A rows with key 1 matches each of the three B rows with key 1, producing rows.
Question 52 of 60 · Inner join · Hard
A contains (k,v) rows (1,10), (2,NULL), (3,20). B contains (1,10), (1,NULL), (2,NULL), (3,30). How many rows result from A JOIN B ON A.k = B.k AND A.v = B.v?
Not quite. Try another option.
Answer: 1
Only (1,10) matches. Comparisons between NULL values evaluate to UNKNOWN, not TRUE, and the rows with key 3 have unequal values.
Question 53 of 60 · Outer join · Hard
Three employees reference departments 10, 20, and 30. Department 10 is active, department 20 is inactive, and department 30 is absent. What does the following return?
SELECT COUNT(*), COUNT(d.id) FROM Employee e LEFT JOIN Department d ON e.dept_id = d.id AND d.active = 1;
Not quite. Try another option.
Answer: (3, 1)
All three employees survive the left join, but only department 10 satisfies the complete join condition. Thus only one joined department ID is non-null.
Question 54 of 60 · Outer join · Hard
A contains keys 1, 1, 2, and B contains keys 1, 3, 3. How many rows are produced by A FULL OUTER JOIN B ON A.key = B.key?
Not quite. Try another option.
Answer: 5
Key 1 produces two matched rows. The unmatched key 2 contributes one row, and the two unmatched key 3 rows contribute two more.
Question 55 of 60 · Cross join · Hard
A contains x = 1, 2, 3, and B contains y = 2, 3. How many rows remain after SELECT * FROM A CROSS JOIN B WHERE A.x < B.y;?
Not quite. Try another option.
Answer: 3
The qualifying pairs are (1,2), (1,3), and (2,3). The cross join creates all six pairs before the WHERE condition filters them.
Question 56 of 60 · GROUP BY clause · Hard
Sales rows are ('E','A',10), ('E','A',NULL), ('E','B',20), (NULL,'A',5), and (NULL,'A',15). Ignoring row order, what does SELECT region, product, COUNT(amount), SUM(amount) FROM Sales GROUP BY region, product; return?
Not quite. Try another option.
Answer: [(NULL,A,2,20), (E,A,1,10), (E,B,1,20)]
Rows with the same grouping values, including NULL grouping values, form one group. COUNT(amount) ignores the null amount in the E/A group.
Question 57 of 60 · GROUP BY clause · Hard
Department A has salaries 10 and 20; department B has salary 100. What is returned by SELECT AVG(dept_avg) FROM (SELECT dept, AVG(salary) AS dept_avg FROM Employee GROUP BY dept) AS D;?
Not quite. Try another option.
Answer: 57.50
The departmental averages are 15 and 100. The outer query averages those two group results equally, producing .
Question 58 of 60 · HAVING clause · Hard
Product A has amounts 10, NULL; B has 5, 15; and C has NULL, NULL. Which products survive GROUP BY product HAVING COUNT(amount) = COUNT(*)?
Not quite. Try another option.
Answer: Product B only
The equality holds only when every row in the group has a non-null amount. Product B has no null amounts.
Question 59 of 60 · HAVING clause · Hard
Table T contains amounts 10, 20, and NULL. What does SELECT COUNT(*) FROM T HAVING AVG(amount) > 12; return when no GROUP BY is present?
Not quite. Try another option.
Answer: One row containing 3
Without GROUP BY, the table forms one group. Its average over non-null values is 15, so the group passes, and COUNT(*) returns 3.
Question 60 of 60 · ORDER BY clause · Hard
Which clause selects the three highest-paid employees deterministically, choosing the lower employee_id first whenever salaries tie?
Not quite. Try another option.
Answer: ORDER BY salary DESC, employee_id ASC FETCH FIRST 3 ROWS ONLY
Descending salary places the highest values first, while ascending employee ID resolves equal-salary ties deterministically before the three-row limit is applied.
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of INT322 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of INT322 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.