1. The document provides examples of SQL queries using various SELECT statements with clauses like WHERE, LIKE, BETWEEN, IN, IS NULL to filter and retrieve data from different database tables.
2. Section 2.1 covers using columns, concatenation, and DISTINCT while section 2.2 introduces the WHERE clause for comparison operators. Section 2.3 demonstrates additional comparison operators like BETWEEN, LIKE, IS NULL, and IN.
3. The examples select fields from tables like customers, cds, songs, and employees to showcase different SQL syntax and functions for querying databases.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
464 views3 pages
DP2 Practice Activities - Answers
1. The document provides examples of SQL queries using various SELECT statements with clauses like WHERE, LIKE, BETWEEN, IN, IS NULL to filter and retrieve data from different database tables.
2. Section 2.1 covers using columns, concatenation, and DISTINCT while section 2.2 introduces the WHERE clause for comparison operators. Section 2.3 demonstrates additional comparison operators like BETWEEN, LIKE, IS NULL, and IN.
3. The examples select fields from tables like customers, cds, songs, and employees to showcase different SQL syntax and functions for querying databases.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
Practice Activity for DP 2.1 – 2.
3 Gery J. Sumual (01123574291-53)
2.1 Working with Columns, Characters, and Rows
Vocabulary: DISTINCT, concatenation operator, string values, DESCRIBE Try It / Solve It: 1. SELECT last_name "Last Name", address ||', '||city||', '||state||'-'||zip||', '||phone_number "Mailing Address" FROM f_customers; 2. a. SELECT first_name FROM f_staffs; b. SELECT first_name||' '||last_name AS "DJs on Demand clients" FROM d_clients; c. SELECT DISTINCT quantity FROM f_order_lines; d. SELECT order_number FROM f_orders; 3. SELECT ' *** '||first_name||' *** '||first_name||' ***' AS "Super Star" FROM f_staffs; 4. d. No rows will be returned (because ‘DISTINCT’ must be right after ‘SELECT’) 5. SELECT last_name "EMPLOYEE LAST NAME", salary "CURRENT SALARY", salary*1.05 "SALARY WITH 5% RAISE" FROM f_staffs; 6. First_name, phone_number, salary, commission_pct, manager_id, department_id, bonus. All these columns could have null value meaning that there could be employees without all these details recorded in the database, possibly the retired employees. 7. SELECT cd_number "Inventory Item", title "CD title", producer "Music Producer", year "Year Purchased" FROM d_cds; 8. TRUE 9. TRUE 10. SELECT employee_id, last_name, salary*12 "ANNUAL SALARY" FROM employees; 11. Salary*12 12. d. both a and b 13. projection 14. c. Employee 15. d. SELECT salary+6*100 16. c. SELECT 'Mr./Ms. '||first_name||' '||last_name ||' '||'is an employee of our company.' AS "Employees" 17. c. Keywords cannot be abbreviated or split across lines. 18. a. SELECT DEPARTMENT_ID, LAST_NAME, FIRST_NAME FROM employees; d. SELECT department_id, last_name, first_name FROM employees; 19. d. SelecT* FROM employees (albeit, no) 20. Done! 2.2 Limit Rows Selected Vocabulary:WHERE clause, comparison operator Try It / Solve It: 1. SELECT first_name, last_name, address FROM f_customers WHERE id = 456; 2. SELECT name, start_date, end_date FROM f_promotional_menus WHERE give_away = 'ballpen and highlighter'; 3. SELECT 'The ‘ ||1997 recording in our database is The Celebrants Live in Concert' AS "Oldest" FROM dual; or SELECT 'The ' || year || ' recording in our database is The Celebrants Live in Concert' AS "Oldest" FROM d_cds WHERE year = (SELECT MIN(year) FROM d_cds); 4. SELECT producer, title FROM d_cds WHERE title = 'Carpe Diem'; 5. SELECT title, year FROM d_cds WHERE year < 2000; 6. 5000 and 0 - 4999 7. SELECT studentno, fname, lname FROM students WHERE sex = 'F'; 8. SELECT studentno “Student Number” FROM students WHERE major = ‘PE’; 9. SELECT* FROM students WHERE sex = ‘M’; 10. SELECT title, year FROM d_cds WHERE year ^= 2000; 11. SELECT* FROM f_staffs WHERE birthdate < '01-Jan-1980'; 2.3 Comparison Operator Vocabulary: ESCAPE, is null and is not null, BETWEEN … AND …, BETWEEN 1 AND 10, LIKE, IN Try It / Solve It: 1. SELECT first_name, last_name, salary FROM f_staffs WHERE salary BETWEEN 5 AND 10; 2. SELECT loc_type, comments FROM d_venus WHERE loc_type = 'Private Home'; 3. SELECT first_name, last_name FROM f_staffs WHERE salary >= 20.00 and salary <= 60.00; 4. SELECT title FROM d_cds WHERE title LIKE '_a%'; 5. SELECT * FROM d_partners WHERE auth_expense_amt IS NULL; 6. SELECT first_name||' '||last_name "Possible Candidates" FROM employees WHERE last_name LIKE '%s'; 7. c. WHERE quantity IS NULL; 8. SELECT* FROM d_songs WHERE type_code IN (77,12,1);