Questions For SQL Part 1
Questions For SQL Part 1
Questions For SQL Part 1
1. What is the correct SQL statement to retrieve the 5th highest salary in a table?
SELECT DISTINCT salary FROM employees ORDER BY salary DESC OFFSET 4 ROWS
FETCH NEXT 1 ROWS ONLY;
SELECT TOP 5 salary FROM employees ORDER BY salary ASC;
SELECT salary FROM employees ORDER BY salary DESC FETCH FIRST 5 ROWS
ONLY;
SELECT salary FROM employees ORDER BY salary ASC FETCH NEXT 1 ROWS ONLY
OFFSET 4 ROWS;
2. The function that an entity plays in a relationship is called that entity’s _____________
Instance
Role
Position
Participation
4. Which SQL keyword is used to combine the results of two queries and return only distinct
rows?
INTERSECT;
UNION;
JOIN;
DISTINCT;
5. FIRST_NAMEVARCHAR2 (50)
LAST_NAMENOT NULLVARCHAR2 (50)
ADDRESSVARCHAR2 (50)
CITYVARCHAR2 (25)
STATEVARCHAR2 (3)
You want to display details of all members who reside in states starting with the letter A
followed by exactly one character.
Which SQL statement must you execute?
SELECT * FROM MEMBERS WHERE state LIKE 'A%';
SELECT * FROM MEMBERS WHERE state LIKE '%A_*;
SELECT * FROM MEMBERS WHERE state LIKE 'A_';
SELECT * FROM MEMBERS WHERE state LIKE 'A_%';
9. In an ER diagram, which of the following is true about the cardinality ratio between
entities?
A many-to-one relationship means each entity in the first set relates to many entities in the
second set;
A one-to-one relationship means every entity in both sets relates to at most one entity in the
other set;
A many-to-many relationship means every entity in both sets is related to exactly one entity
in the other set;
A one-to-many relationship means each entity in the second set relates to many entities in the
first set;
10. Which of the following SQL queries will return the first three characters of FirstName
and the Salary rounded to one decimal place from the Employee table?
SELECT SUBSTRING (FirstName, 1, 3), ROUND (Salary, 0.1) FROM Employee;
SELECT LEFT (FirstName, 3), ROUND(Salary, 1) FROM Employee;
SELECT SUBSTR (FirstName, 3, 1), ROUND (Salary, 1) FROM Employee;
SELECT SUBSTR (FirstName, 1, 3), ROUND (Salary, 1) FROM Employee;
11. Which SQL clause is used to filter the rows retrieved by a SELECT statement?
HAVING
WHERE
GROUP BY
ORDER BY
12. Which of the following clauses is used to filter records after the aggregation using the
GROUP BY clause?
DISTINCT;
ORDER BY;
HAVING;
WHERE;
22. Given the table Employee: Employee(EmpID INT, FirstName VARCHAR(30), Salary
DECIMAL(10, 2)). What will be the output of the following query?
SELECT CONCAT(UPPER(SUBSTR(FirstName, 1, 1)), LOWER(SUBSTR(FirstName,
2))), ROUND(Salary, 0) FROM Employee WHERE EmpID = 200; Assume FirstName is
'jessica' and Salary is 45678.89 for EmpID = 200.
JESSICA | 45679
Jessica | 45679
JESSICA | 45678
Jessica | 45678
27. Which of the following queries retrieves the employees who were hired most recently?
SELECT employee_name FROM employees WHERE hire_date = (SELECT
MAX(hire_date) FROM employees);
SELECT employee_name FROM employees WHERE hire_date = CURDATE();
SELECT employee_name FROM employees WHERE hire_date = NOW();
SELECT employee_name FROM employees ORDER BY hire_date ASC;
28. Which of the following statements correctly finds the employee with the second-highest
salary?
SELECT salary FROM employees ORDER BY salary DESC LIMIT 1, 1;
SELECT salary FROM employees ORDER BY salary ASC LIMIT 1, 1;
SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM
employees);
SELECT MAX(salary) FROM employees;
33. Which SQL function can be used to find the position of a substring within a string?
SUBSTR()
LOCATE()
INSTR()
POSITION()
35. View the Exhibit and examine the structure of the ORDER_ITEMS table. (Choose the
best answer.)
You must select the ORDER_ID of the order that has the highest total value among all the
orders in the ORDER_ITEMS table.
Which query would produce the desired result?
SELECT order_idFROM order_itemsWHERE(unit_price*quantity) =
MAX(unit_price*quantity)GROUP BY order_id);
SELECT order_idFROM order_itemsWHERE(unit_price*quantity) = (SELECT MAX
(SUM(unit_price*quantity)FROM order_items) GROUP BY order_id);
SELECT order_idFROM order_itemsGROUP BY order_idHAVING
SUM(unit_price*quantity) = (SELECT MAX (SUM(unit_price*quantity))FROM
order_items
SELECT order_idFROM order_itemsWHERE (unit_price*quantity) = (SELECT
MAX(unit_price*quantity)FROM order_itemsGROUP BY order_id)
36. Given the table OrderDetails: OrderDetails(OrderID INT, Item VARCHAR(30), Quantity
INT, UnitPrice DECIMAL(8, 2)).What will be the output of the following query?
SELECT LOWER(Item), ROUND(UnitPrice * Quantity, -1) FROM OrderDetails WHERE
OrderID = 501;
Assume Item is 'Refrigerator' with Quantity = 3 and UnitPrice = 749.99 for OrderID = 501.
refrigerator | 2240
refrigerator | 2250.0
REFRIGERATOR | 2250
refrigerator | 2250
37. Which of the following statements retrieves all the rows from a table named employees?
SELECT * FROM employees;
SELECT employees FROM *;
SELECT ALL FROM employees;
SELECT ALL (*) FROM employees;
41. In the context of an ER model, a "weak entity" can be best described as:?
An entity that lacks a candidate key and must rely on an identifying relationship;
An entity that can exist independently of other entities;
An entity that has a primary key but no foreign key;
An entity with a composite primary key;
42. Which SQL function is used to return the position of the first occurrence of a substring
within a string?
FIND;
POSITION;
LOCATE;
INSTR;
43. How the Every weak entity set can be changed into a strong entity set through?
adding appropriate attributes
none of the above
using aggregation
using generalization
44. How can you select rows that meet at least one of several conditions?
Using OR
Using NOT
Using BETWEEN
Using AND
45. Which SQL clause is used to group rows that have the same values into summary rows?
ORDER BY;
GROUP BY;
HAVING;
WHERE;
46. How do you select rows from a table where a column value is NULL?
SELECT * FROM table WHERE column != NULL;
SELECT * FROM table WHERE column = '';
SELECT * FROM table WHERE column = NULL;
SELECT * FROM table WHERE column IS NULL;
49. Which of the following statements about an Entity-Relationship (ER) model is true?
A composite attribute can have multiple values for each entity;
A weak entity set must have a primary key;
A relationship set always contains attributes;
A derived attribute is calculated from other attributes;
50. How do you rename a column in the result set in Oracle SQL?
ALTER
SET
AS
RENAME
51. Which SQL clause is used to group rows with the same values into summary rows?
ORDER BY
WHERE
HAVING
GROUP BY
54. Which keyword is used to eliminate duplicate rows in the result set?
DELETE
DISTINCT
UNIQUE
REMOVE
56. Which two statements are true regarding the GROUP BY clause in a SQL statement?
(Choose two.)
You can use column alias in the GROUP BY clause.
The GROUP BY clause is mandatory if you are using an aggregate function in the SELECT
clause.
Using the WHERE clause after the GROUP BY clause excludes the rows after creating
groups.
Using the WHERE clause before the GROUP BY clause excludes the rows before creating
groups.
58. A______is a set of relationships of the same type among several entities
Domain
Value Set
Key set
Relationship
59. Given the table Sales: Sales(SaleID INT, ProductName VARCHAR(50), Quantity INT,
Price DECIMAL(8, 2)). What will be the output of the following query?
SELECT LENGTH(ProductName), ROUND(Price * Quantity, -2) FROM Sales WHERE
SaleID = 301; Assume ProductName is 'Laptop' with Quantity = 5 and Price = 899.99 for
SaleID = 301.
7 | 4500
6 | 45000
6 | 450000
6 | 4500
62. Which of the following represents a correct mapping from an ER diagram to a relational
model?
Each entity set, whether strong or weak, always maps to an individual table;
Each strong entity set maps to a separate table, while weak entity sets map to a table along
with the strong entity's primary key;
Composite attributes are always mapped as separate tables;
Relationship sets never require a separate table;
66. Given the table Employee: Employee (EmpID INT, FirstName VARCHAR (30),
LastName VARCHAR (30), Salary DECIMAL (10, 2))
Which query will return the LastName in uppercase and the Salary rounded to the nearest
hundred?
SELECT INITCAP(LastName), ROUND (Salary, -2) FROM Employee;
SELECT LOWER(LastName), ROUND(Salary, 2) FROM Employee;
SELECT UPPER(LastName), ROUND(Salary, 0) FROM Employee;
SELECT UPPER(LastName), ROUND (Salary, -2) FROM Employee;
69. Each student can work on multiple projects and each project can have multiple students.
You need to design an Entity Relationship Model (ERD) for optimal data storage and allow
for generating reports in this format:
STUDENT_ID FIRST_NAME LAST_NAME PROJECT_ID PROJECT_NAME
PROJECT_TASK
Which two statements are true in this scenario?
STUDENT_ID must be the primary key in the STUDENTS entity and foreign key in the
PROJECTS entity.
PROJECT_ID must be the primary key in the PROJECTS entity and foreign key in the
STUDENTS entity
The ERD must have a 1:M relationship between the STUDENTS and PROJECTS entities.
The ERD must have a M:M relationship between the STUDENTS and PROJECTS entities
that must be resolved into 1:M relationships.
73. The attribute name could be structured as an attribute consisting of first name, middle
initial, and last name. This type of attribute is called
Simple attributeOption
Multivalued attribute
Composite attribute
Derived attribute
74. Which of the following SQL functions can be used to get the current date and time in
Oracle?
GETDATE()
CURRENT_DATE()
SYSDATE()
NOW()