




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
all the topics under mod 3 in ooc is covered
Typology: Study notes
1 / 36
This page cannot be seen from the preview
Don't miss anything!
Nested Queries, Tuples, and Set/Multiset Comparisons
Nested Queries::Comparison Operators
EXISTS Functions (^) The EXISTS function in SQL is used to check whether the result of a correlated nested query is empty (contains no tuples) or not. The result of EXISTS is a Boolean value TRUE if the nested query result contains at least one tuple, or FALSE if the nested query result contains no tuples. (^) For example, the query to retrieve the name of each employee who has a dependent with the same first name and is the same gender as the employee can be written using EXISTS functions as follows: SELECT E.Fname, E.Lname FROM EMPLOYEE AS E WHERE EXISTS ( SELECT *FROM DEPENDENT AS D WHERE E.Ssn=D.Essn AND E.Gender=D.Gender AND E.Fname=D.Dependent_name )
Explicit Sets and Renaming of Attributes in SQL
Joined Tables in SQL and Outer Joins (^) A JOIN is a means for combining fields from two tables by using values common to each. SQL specifies four types of JOIN.
(^) An inner join is the most common join operation used in applications and can be regarded as the default join type. (^) Inner join creates a new result table by combining column values of two tables (A and B) based upon the join- predicate (the condition). (^) The result of the join can be defined as the outcome of first taking the Cartesian product (or Cross join) of all records in the tables (combining every record in table A with every record in table B) then return all records which satisfy the join predicate. (^) Example: SELECT * FROM employee INNER JOIN department ON employee.dno = department.dnumber; Joined Tables in SQL and Outer Joins
(^) CROSS JOIN returns the Cartesian product of rows from tables in the join. In other words, it will produce rows which combine each row from the first table with each row from the second table. OUTER JOIN (^) An outer join does not require each record in the two joined tables to have a matching record. The joined table retains each record-even if no other matching record exists. Outer joins subdivide further into (^) Left outer joins (^) Right outer joins (^) Full outer joins Joined Tables in SQL and Outer Joins
Joined Tables in SQL and Outer Joins
Joined Tables in SQL and Outer Joins
(^) It is also possible to nest join specifications; that is, one of the tables in a join may itself be a joined table. This allows the specification of the join of three or more tables as a single joined table, which is called a multiway join. Joined Tables in SQL and Outer Joins
Aggregate Functions in SQL
Grouping: The GROUP BY and HAVING Clauses (^) Grouping is used to create subgroups of tuples before summarization. For example, we may want to find the average salary of employees in each department or the number of employees who work on each project. (^) SQL has a GROUP BY clause for this purpose. (^) The GROUP BY clause specifies the grouping attributes, which should also appear in the SELECT clause, so that the value resulting from applying each aggregate function to a group of tuples appears along with the value of the grouping attribute(s).