This document contains practice problems and explanations for Oracle SQL joins, including equijoins, Cartesian products, non-equijoins, and outer joins. It provides 12 examples of join queries with explanations. The examples demonstrate selecting records from multiple tables where the join conditions match or are non-equal and use both implicit and explicit outer joins. The document also discusses using table aliases and correcting syntax issues.
This document contains practice problems and explanations for Oracle SQL joins, including equijoins, Cartesian products, non-equijoins, and outer joins. It provides 12 examples of join queries with explanations. The examples demonstrate selecting records from multiple tables where the join conditions match or are non-equal and use both implicit and explicit outer joins. The document also discusses using table aliases and correcting syntax issues.
This document contains practice problems and explanations for Oracle SQL joins, including equijoins, Cartesian products, non-equijoins, and outer joins. It provides 12 examples of join queries with explanations. The examples demonstrate selecting records from multiple tables where the join conditions match or are non-equal and use both implicit and explicit outer joins. The document also discusses using table aliases and correcting syntax issues.
This document contains practice problems and explanations for Oracle SQL joins, including equijoins, Cartesian products, non-equijoins, and outer joins. It provides 12 examples of join queries with explanations. The examples demonstrate selecting records from multiple tables where the join conditions match or are non-equal and use both implicit and explicit outer joins. The document also discusses using table aliases and correcting syntax issues.
Vocabulary: Cartesian Product, equijoin, proprietry join, alias, join conditions Try It / Solve It: 1. SELECT* FROM d_play_list_items, d_track_listings; 2. SELECT* FROM d_play_list_items plim, d_track_listings tlg WHERE plim.song_id = tlg.song_id; 3. SELECT title, type_code, description, artist FROM d_songs, d_types WHERE code = type_code; 4. SELECT title, type_code, description, artist FROM d_songs, d_types WHERE code = type_code and id IN (47,48); 5. SELECT* FROM d_clients dcet, d_events devt, d_job_assignments djamt WHERE dcet.client_number = devt.client_number AND devt.id = djamt.event_id; 6. SELECT song_id, title FROM d_track_listings dtltg, d_cds dcd WHERE dtltg.cd_number = dcd.cd_number; 7. a. T; b. T; c. F; d. F; e. T; f. F; g. T 8. Getting more comprehensive data, and in turn, more useful and correct information could be gleaned.
7.2 Oracle Non-equijoins and Outer Joins
Try It / Solve It: 1. SELECT name, code FROM d_events, d_packages WHERE package_code = code; 2. SELECT last_name, salary, grade_level||' ('||lowest_sal||' - '||highest_sal||')' AS job_grade FROM employees, job_grades WHERE salary BETWEEN lowest_sal AND highest_sal; 3. Inequality 4. WHERE a.ranking >= g.lowest_rank AND a.ranking <= g.highest_rank 5. It’s all for conveniency, if the table name is too long then make shorter recognizable alias out of it, but if the the table name is short making an alias for it will amount for nothing but confusion. 6. Nonequijoin 7. SELECT id, first_name||' '||last_name AS customer, order_number, order_date, order_total, staff_id FROM f_customers, f_orders WHERE id = cust_id (+); 8. SELECT last_name, epe.department_id, department_name FROM employees epe, departments dpt WHERE epe.department_id = dpt.department_id (+); 9. SELECT last_name, epe.department_id, department_name FROM employees epe, departments dpt WHERE epe.department_id (+) = dpt.department_id ORDER BY last_name DESC; 10. a. WHERE e.department_id(+) = d.department_id (+); Oracle proprietry outer join predicate (+) can only outer-joined one table at a time. Correction: WHERE e.department_id = d.department_id (+); (equals to ANSI’s LEFT OUTER JOIN) WHERE e.department_id(+) = d.department_id; (equals to ANSI’s RIGHT OUTER JOIN) b. SELECT e.employee id, e. last name, d. location id FROM employees, departments WHERE e.department_id = d.department_id(+); Both the table names in FROM clause don’t have an alias, so the table alias used in other clauses of the statement will yield errors. Correction: SELECT e.employee id, e. last name, d. location id FROM employees e, departments d WHERE e.department_id = d.department_id(+); 11. SELECT dcd.title, dsng.id AS song_id FROM d_songs dsng, d_track_listings dtlg, d_cds dcd WHERE dsng.id = dtlg.song_id AND dcd.cd_number = dtlg.cd_number; Or SELECT dcd.title, dtlg.song_id AS song_id FROM d_cds dcd, d_track_listings dtlg WHERE dcd.cd_number = dtlg.cd_number; 12. For me it would be between scientist and computer programmer.