Test SQL: - Part 1 SQL/ DWH Basis
Test SQL: - Part 1 SQL/ DWH Basis
4. Find the SQL statement below that is equal to the following: SELECT name FROM customer WHERE state = 'VA';
A.SELECT name IN customer WHERE state IN ('VA');
B.SELECT name IN customer WHERE state = 'VA';
C.SELECT name IN customer WHERE state = 'V';
D.SELECT name FROM customer WHERE state IN ('VA');
6. With SQL, how do you select a column named "FirstName" from a table named "Persons"?
7. With SQL, how do you select all the columns from a table named "Persons"?
A) SELECT * FROM Persons
B) SELECT Persons
C) SELECT *.Persons
D) SELECT [all] FROM Persons
12. What does the following SQL statement do: SELECT Customer, COUNT (Order) FROM Sales GROUP BY Customer HAVING COUNT(Order) >5
A) Selects all Customers from the Sales table
B) Selects all customers from table Sales that have made more than 5 orders.
C) Selects the total number of orders from the Sales table, if this number is greater than 5
14. You issue the following command to drop the PRODUCTS table: SQL>DROP TABLE products; What is the implication of this command? (Choose
all that apply.)
A) All data in the table are deleted but the table structure will remain
B) All data along with the table structure is deleted
C) All views and synonyms will not remain but they are invalidated
D) All indexes on the table will remain but they are invalidated
18. Examine the structure of the EMPLOYEES table: Which UPDATE statement is valid?
A) UPDATE employees SET first_name = ‘John’ SET last_name = ‘Smith’ WHERE employee_id = 180;
B) UPDATE employees SET first_name = ‘John’, SET last_name = ‘Smoth’ WHERE employee_id = 180;
C) UPDATE employee SET first_name = ‘John’ AND last_name = ‘Smith’ WHERE employee_id = 180;
D) UPDATE employee SET first_name = ‘John’, last_name = ‘Smith’ WHERE employee_id = 180;
19. Evaluate the SQL statement: TRUNCATE TABLE DEPT; Which one is true about the SQL statement?
A) It releases the storage space used by the table
B) You can roll back the deletion of rows after the statement executes.
C) You can NOT roll back the deletion of rows after the statement executes.
D) An attempt to use DESCRIBE on the DEPT table after the TRUNCATE statement executes will display an error.
20. For which action, can you use the TO_DATE function?
A) Convert any date literal to a date
B) Convert any numeric literal to a date
C) Convert any character literal to a date
D) Convert any date to a character literal
1. View the Exhibit and examine the structure of the EMP and SALGRADE tables. You want to display the names of all employees whose
salaries belong to GRADE 5. Which SQL statements give the required output? (Choose all that apply)
A.SELECT ename
FROM emp JOIN salgrade
USING (sal BETWEEN losal AND hisal) AND grade = 5;
B.SELECT ename
FROM emp e JOIN salgrade s
ON (e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5);
C. SELECT ename
FROM emp e JOIN salgrade s
ON (e.sal BETWEEN s.losal AND s.hisal) AND s.grade = 5;
D. SELECT ename
FROM emp e JOIN salgrade s
ON (e.sal BETWEEN s.losal AND s.hisal) WHERE s.grade=5;
E.SELECT ename
FROM emp e JOIN salgrade s
WHERE e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5;
1a "Exhibit"
EMP
SALGRADE
Name Null? Type
GRADE NUMBER
LOSAL NUMBER
HISAL NUMBER
2. View the Exhibit and examine the structure of the DEPARTMENTS and LOCATIONS tables. You want to display all the cities and the
corresponding departments in them, if any. Which query would give you the required output?
A.SELECT location_id LOC, city, department_id DEPT
FROM locations LEFT OUTER JOIN departments
USING (location_id);
B.SELECT location_id LOC, city, department_id DEPT
FROM locations RIGHT OUTER JOIN departments
USING (location_id);
C. SELECT l.location_id LOC, l.city, d.department_id DEPT
FROM locations l LEFT OUTER JOIN departments d
USING (location_id);
D. SELECT l.location_id LOC, l.city, d.department_id DEPT
FROM locations l FULL OUTER JOIN departments d
USING (location_id);
2a "Exhibit"
DEPARTMENTS
LOCATIONS
3. View the Exhibit and examine the structure of the EMPLOYEES and DEPARTMENTS tables. You want to display the last names and
hire dates of all latest hires in their respective departments in the location ID 1700. You issue the following query:
3a "Exhibit"
EMPLOYEES
4. View the Exhibit and examine the structure of the LOCATIONS and DEPARTMENTS tables. You need to display all those cities that
have only one department. Which query gives the correct output?
A.SELECT location_id, city
FROM locations l
WHERE 1 = (SELECT COUNT(*)
FROM departments
WHERE location_id = l.location_id);
B.SELECT location_id, city
FROM locations WHERE EXISTS (SELECT COUNT(*)
FROM departments
GROUP BY location_id HAVING COUNT(*) = 1);
C. SELECT location_id, city
FROM locations WHERE
1 = (SELECT COUNT(*) FROM departments
GROUP BY location_id);
D. SELECT l.location_id, city
FROM locations l JOIN departments d ON (l.location_id = d.location_id)
WHERE EXISTS (SELECT COUNT(*)
FROM departments d
WHERE l.location_id =d.location_id);
4a "Exhibit"
LOCATIONS
DEPARTMENTS
5. View the Exhibit and examine the structure of the EMP table. You want to display the names and salaries of only those employees who
earn the highest salaries in their departments. Which two SQL statements give the required output? (Choose two.)
A.SELECT ename, sal
FROM emp e
WHERE sal = (SELECT MAX(sal)
FROM emp
WHERE deptno = e.deptno);
B.SELECT ename, sal
FROM emp
WHERE sal = ALL (SELECT MAX(sal)
FROM emp
GROUP BY deptno);
C. SELECT ename, sal
FROM emp e
WHERE EXISTS (SELECT MAX(sal)
FROM emp WHERE deptno = e.deptno);
D. SELECT ename, sal
FROM emp
NATURAL JOIN (SELECT deptno, MAX(sal) sal
FROM emp
GROUP BY deptno) ;