Which SQL command is used to retrieve data from a database?
SQL Queries — Important Questions
SUMMARY: This chapter focuses on teaching students how to write and execute SQL queries to manage and manipulate databases.
KEY TOPICS: SQL syntax, SELECT statement, WHERE clause, JOIN operations, GROUP BY clause, ORDER BY clause, INSERT statement, UPDATE statement, DELETE statement, aggregate functions
Which SQL clause is used to filter records?
Check answerHide answer
Which SQL keyword is used to sort the result-set in ascending order by default?
Check answerHide answer
The SQL command used to add a new row to a table is:
Check answerHide answer
Which SQL function returns the total number of rows in a column?
Check answerHide answer
Differentiate between DDL and DML commands with two examples each.
Write a SQL query to display all rows from the table employee.
Differentiate between WHERE and HAVING clauses.
Write a SQL query to find the total number of employees in each department from a table employee(emp_id name dept salary).
Explain the use of DISTINCT keyword in SQL with one example.
Discuss any five SQL aggregate functions with examples on a sample employee table.
Differentiate between INNER JOIN LEFT JOIN and RIGHT JOIN with one example each.
Write SQL queries to: (a) create a table student (b) insert 3 rows (c) update marks of one student (d) delete a student (e) display students with marks > 80.
Explain GROUP BY and HAVING clauses with examples.
Discuss constraints in SQL — PRIMARY KEY FOREIGN KEY UNIQUE NOT NULL CHECK DEFAULT — with one example each.
Differentiate between DDL and DML SQL commands in tabular form with examples.
Assertion (A): SELECT is a DQL (Data Query Language) command.
Reason (R): It is used to retrieve data from one or more tables.
Show explanationHide explanation
Assertion (A): GROUP BY groups rows with same value in a column.
Reason (R): It is often used with aggregate functions.
Show explanationHide explanation
Assertion (A): COUNT(*) returns the total number of rows including NULLs.
Reason (R): COUNT(column) ignores NULL values in that column.
Show explanationHide explanation
Assertion (A): DELETE removes rows from a table.
Reason (R): DROP removes the entire table including its structure.
Show explanationHide explanation
Assertion (A): The LIKE operator is used for pattern matching.
Reason (R): Wildcard % matches any sequence of characters.
Show explanationHide explanation
Statement 1: DDL commands include CREATE ALTER and DROP.
Statement 2: They define and modify the structure of a database.
Show answerHide answer
Statement 1: DML commands include INSERT UPDATE and DELETE.
Statement 2: They modify the data within tables.
Show answerHide answer
Statement 1: WHERE filters rows before grouping.
Statement 2: HAVING filters groups after aggregation.
Show answerHide answer
Statement 1: A NULL value is different from zero or empty string.
Statement 2: It represents missing or unknown data.
Show answerHide answer
Statement 1: JOIN combines rows from two or more tables based on a related column.
Statement 2: Different types include INNER LEFT RIGHT and FULL OUTER joins.
Show answerHide answer
-
Which SQL command retrieves data from a table?ASELECTBGETCFETCHDRETRIEVE
-
Which clause is used to filter individual rows?AWHEREBHAVINGCGROUP BYDORDER BY
-
Write the SQL queries for all four HR requirements.
Show answersHide answers
For the sample employee table compute the result of each SQL query.
| emp_id | name | dept | salary |
|---|---|---|---|
| 1 | Anil | IT | 50000 |
| 2 | Bobby | HR | 40000 |
| 3 | Chitra | HR | 35000 |
| 4 | Geeta | IT | 60000 |
| 5 | Hari | Sales | 40000 |
Match each SQL clause with its purpose.
| Clause | Purpose |
|---|---|
| SELECT | ? |
| WHERE | ? |
| GROUP BY | ? |
| HAVING | ? |
| ORDER BY | ? |
| LIMIT | ? |
For the sample table evaluate each SQL aggregate query.
| Query | Result |
|---|---|
| COUNT(*) | ? |
| SUM(salary) | ? |
| AVG(salary) | ? |
| MAX(salary) | ? |
| MIN(salary) | ? |
| COUNT(DISTINCT dept) | ? |
Match SQL command type (DDL/DML/DCL/DQL/TCL) for each.
| Command | Type |
|---|---|
| CREATE | ? |
| INSERT | ? |
| SELECT | ? |
| GRANT | ? |
| COMMIT | ? |
| DROP | ? |
| UPDATE | ? |
Study the SQL JOIN Venn diagrams and answer:
-
Which JOIN returns only matching rows from both tables?AINNER JOINBLEFT JOINCFULL JOINDCROSS JOIN
-
Which JOIN returns all rows from the left table plus matches from the right?AINNERBLEFTCRIGHTDFULL
-
Differentiate between INNER LEFT RIGHT and FULL JOINs with examples.
Show answersHide answers
Study the SQL execution order diagram and answer:
-
Which clause is executed FIRST?ASELECTBFROMCWHEREDORDER BY
-
Which clause filters AGGREGATED groups?AWHEREBHAVINGCGROUP BYDORDER BY
-
Discuss the logical execution order of SQL clauses and explain WHERE vs HAVING.
Show answersHide answers
Make a full Computer Science paper on SQL Queries.
Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.
Generate your paper — free