Handout 9 CS-605 Spring 18 Page 1 of 8. Handout 9. SQL Select -- Multi Table Queries. Joins and Nested Subqueries.
|
|
- Melvin Anthony
- 6 years ago
- Views:
Transcription
1 Handout 9 CS-605 Spring 18 Page 1 of 8 Handout 9 SQL Select -- Multi Table Queries. Joins and Nested Subqueries. Joins In Oracle Many queries need to access data from more than one table. To combine (or join) two or more tables in a query: equi-join - connects tuples based on the equality of the attributes of rows in two tables. Most often it involves the equality between a foreign key of one table to a primary key of another. Example: Display the names of all employees along with the name of the department in which they are working. SELECT emp_fname emp_lname, dept_name FROM employee, dept WHERE emp_dept= dept_nbr; emp_deptis the foreign key in the EMPLOYEE table that references the dept_nbr pri- mary key of the DEPT_table. Aletrnative syntax (uses the JOIN operation in the FROM clause) SELECT E.emp_fname ' ' E.emp_lname, D.dept_name FROM employee JOIN dept ON emp_dept = dept_nbr; In the queries above emp_dept= dept_nbr is the join condition, it ties together the rows of the two tables. Note that the first query can be written in the following way, where each column name is prefixed with the name of the table from which the column is taken: or as SELECT EMPLOYEE.emp_fname EMPLOYEE.emp_lname, DEPT.dept_name FROM EMPLOYEE, DEPT WHERE EMPLOYEE.emp_dept= DEPT.dept_nbr; SELECT E.emp_fname E.emp_lname, D.dept_name FROM EMPLOYEE E, DEPT D WHERE E.emp_dept = D.dept_nbr; Such prefix is necessary if two tables have columns with the same name.
2 Handout 9 CS-605 Spring 18 Page 2 of 8 When the WHERE clause is missing or does not contain a join condition, the result is a cross join (a.k.a. Cartesian product) of the two tables: a set of rows that includes every possible row combination from the two tables. In other words, each row from one table is conjoined with each row of the other. Example: what will be produced by the following query? How many rows will be selected assuming that the EMPLOYEE table has 16 rows the DEPT table has 7 rows? SELECT emp_fname emp_lname, dept_name FROM EMPLOYEE, DEPT Note that the WHERE clause may contain conditions other than the join condition. Example: Display the names of those employees that work in building G SELECT emp_fname emp_lname FROM EMPLOYEE, DEPT WHERE emp_dept= dept_nbr and dept_building = G ; More than two tables can be joined together. Example: Display the names of those customer representatives who work with customers from California. For each representative also display the building in which they work. SELECT emp_fname emp_lname, dept_building FROM EMPLOYEE, DEPT, CUSTOMER WHERE cust_state = CA and cust_rep = emp_nbr and emp_dept= dept_nbr ORDER BY cust_rep; Q: Is the result going to possibly contain duplicates? How would you verify correctness of this query? Here is a more complex examples that demonstrates multi-table grouping: Example: Display the number and name of each customer and the total amount of last year s sales to that customer. SELECT cust_nbr, cust_name, SUM (sales_last_year) FROM SALES, CUSTOMER WHERE cust_nbr = sales_cust_nbr GROUP BY cust_nbr, cust_name; Q: Are the customers with no sales records (i.e. 0 sales) going to be included in the result?
3 Handout 9 CS-605 Spring 18 Page 3 of 8 Practice problems: 1. What result is generated by the following queries? select Emp_nbr, Emp_lname, Emp_fname from EMPLOYEE, CUSTOMER, SALES where Emp_nbr = Cust_rep and Cust_nbr = Sales_Cust_nbr and Sales_prod_nbr = 60; select Cust_name, Cust_phone, sum(sales_last_year) from CUSTOMER, SALES, PRODUCT where Cust_nbr = Sales_cust_nbr and Sales_prod_nbr = Prod_nbr and Prod_prodline between 10 and 19 group by Cust_nbr, Cust_name, Cust_phone having count(sales_last_year) > 3 order by count(sales_last_year) desc; 2. Print department name, department manager name and department phone number for all departments. 3. Display the customer number and phone of those customers who bought products from product lines 21, 22 and 23. A table can be joined with itself (self-join, sometimes necessary). Then, the FROM clause must list the same table twice, giving each table instance a separate name, so that two diff t rows in the same table could be referenced Example: Display all employees who are married to another employee, together with the name of their spouse: SELECT E1.emp_fname E1.emp_lname, E2.emp_fname E2.emp_lname FROM EMPLOYEE E1, EMPLOYEE E2, MARRIAGE M WHERE M.emp1_nbr = E1.emp_nbr and M.emp2_nbr = E2.emp_nbr;
4 Handout 9 CS-605 Spring 18 Page 4 of 8 Here s another example where aliasing is necessary: Example: Display all pairs of customers that have the same customer representative: SELECT C1.cust_name, C2.cust_name FROM CUSTOMER C1, CUSTOMER C2 WHERE C1.cust_rep = C2.cust_rep Practice problem: What would be the result if customer table was not aliased, i.e. SELECT cust_name, cust_name FROM CUSTOMER WHERE cust_rep = cust_rep; Nested Subqueries Some SELECT statements include nested SELECT subqueries in the WHERE, or HAVING clause. The result of the subquery is either 1. a number, generated by an aggregate fn. (COUNT, SUM, AVE, MIN, MAX). Example: Display the names of those employees that have the highest number of dependents. Hint: an employee has the highest number of dependents if his number of dependents equals the maximum number of dependents across the entire company. SELECT emp_fname ' ' emp_lname, emp_nbr_of_dependents FROM EMPLOYEE WHERE emp_nbr_of_dependents = (SELECT MAX(emp_nbr_of_dependents) FROM EMPLOYEE) Example: Display the names of those customers who bought the most expensive product Hint: generate the price of the most expensive products; select those customers who have sales records that refer to a product from that list. SELECT DISTINCT cust_name FROM CUSTOMER, SALES,PRODUCT WHERE cust_nbr = sales cust_nbr AND sales prod_nbr = prod_nbr AND prod_price = (SELECT MAX (prod_price) FROM PRODUCT) 2. a set of rows. Example Display the names of all customer representatives SELECT emp_fname emp_lname FROM EMPLOYEE WHERE emp_nbr IN (SELECT cust_rep FROM CUSTOMER )
5 Handout 9 CS-605 Spring 18 Page 5 of 8 Note the use of operator ALL and the subquery in the next example: Example Display the name of the customer representative(s) that has(ve) the greatest number of customers SELECT cust_rep, emp_fname emp_lname As "NAME", count(cust_nbr) As "Total customers" FROM CUSTOMER,EMPLOYEE WHERE emp_nbr = cust_rep GROUP BY cust_rep, emp_lname, emp_fname HAVING count(cust_nbr) >= ALL ( SELECT count(*) FROM CUSTOMER GROUP BY cust_rep) ; The above examples are examples in which the inner query does not refer to any column values from the outer query - these are called non-correlated subqueries. There are also correlated subqueries - those that refer to a column value from the outer query: Example: Display the names of those customers who bought the most expensive product in the product line. Hint: join the customer and sales tables with the product table and pick records with most expensive product per product line. SELECT DISTINCT cust_name FROM CUSTOMER, SALES, PRODUCT P1 WHERE cust_nbr = sales_cust_nbr AND sales_prod_nbr = P1.prod_nbr AND P1.prod_price = (SELECT MAX(P2.prod_price) FROM PRODUCT P2 WHERE P2.prod_prodline = P1.prod_prodline ); And, the same as above, but also showing the product line and the price of the most expensive item in it using a subquery in the SELECT clause SELECT DISTINCT cust_name, P1.prod_prodline, (SELECT MAX(P2.prod_price) FROM PRODUCT P2 WHERE P2.prod_prodline = P1.prod_prodline ) AS "Max Price" FROM CUSTOMER, SALES, PRODUCT P1 WHERE cust_nbr = sales_cust_nbr AND sales_prod_nbr = P1.prod_nbr AND P1.prod_price = (SELECT MAX(P2.prod_price) FROM PRODUCT P2 WHERE P2.prod_prodline = P1.prod_prodline );
6 Handout 9 CS-605 Spring 18 Page 6 of 8 Example: Display the names of those employees that have the highest number of dependents in their department. Hint: an employee has the highest number of dependents if his number of dependents equals the maximum number of dependents across other employees in his/her department. Practice problems: SELECT E1.emp_fname E1.emp_lname, E1.emp_nbr_of_dependents FROM EMPLOYEE E1 WHERE E1.emp_nbr_of_dependents = ( SELECT MAX(E2.emp_nbr_of_dependents) FROM EMPLOYEE E2 WHERE E2.emp_dept= E1.emp_dept) 1. What is produced by the following queries: select Cust_nbr, Cust_name from CUSTOMER where Cust_nbr NOT IN (select sales_cust_nbr from SALES); select Prod_nbr, Prod_name, Prodline_name from PRODUCT P1, PRODLINE where Prod_prodline = Prodline_nbr and Prod_price < 0.5* (SELECT avg(prod_price) FROM PRODUCT P2 WHERE P2.prod_prodline = P1.prod_prodline); 3. Display the names of all employees that are not department managers. 4. Display the names and phone numbers of those customers who had the smallest number of the total sales in their customer group.
7 Handout 9 CS-605 Spring 18 Page 7 of 8 Set Operations Build result sets based on two or multiple separate queries. Three operations UNION Every row from either table will be included in the answer set INTERSECT Every row that is in both tables will be included in the answer set MINUS Every row that is in the first table but not in the second table will be included in the answer set Requirements for set compatibility The same number of columns The same data types Returns result sets of each select sequentially Outer Join Outer Joins - an operation on two tables that includes rows that do not have matching values in the joined table as well as those that have. LEFT OUTER JOIN - includes non-matching rows from the first table. RIGHT OUTER JOIN - includes non-matching rows from the second table. Syntax of the outer joins varies by RDBMS (and version). The same result can always be derived using combination of UNION and NOT IN operators. Example: common join (a.k.a equi-join, a.k.a inner join ): Display customer representatives numbers, names along with the customers they serve. SELECT emp_nbr, emp_fname emp_lname, cust_nbr, cust_name FROM employee, customer WHERE emp_nbr = cust_rep Same query, but alternative syntax - note the FROM clause has the join condition SELECT emp_nbr, emp_fname emp_lname, cust_nbr, cust_name FROM employee JOIN customer ON emp_nbr = cust_rep Example: LEFT OUTER JOIN: Display all employee numbers and names along with the customers they serve, including information on non-customer representative employees as well. Notice the use of (+). SELECT emp_nbr, emp_fname ' ' emp_lname, cust_name FROM employee, customer WHERE emp_nbr = cust_rep (+)
8 Handout 9 CS-605 Spring 18 Page 8 of 8 Alternative syntax for the LEFT OUTER JOIN. Same query as above. SELECT emp_nbr, emp_fname ' ' emp_lname, cust_name FROM EMPLOYEE LEFT OUTER JOIN Customer ON emp_nbr = cust_rep Alternative way of generating the same information, uses UNION and NOT IN operators. The first SELECT-statement generates the equi-join result, second SELECTstatement generates the rows without matching values SELECT emp_nbr, emp_fname ' ' emp_lname, cust_name FROM employee, customer WHERE emp_nbr = cust_rep UNION SELECT emp_nbr, emp_fname ' ' emp_lname, NULL FROM employee WHERE emp_nbr NOT IN (SELECT cust_rep FROM customer) Practice problem: Display the total number of sales records for each product (there are products for which there is no record in the Sales table).
SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design
SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS The foundation of good database design Outline 1. Relational Algebra 2. Join 3. Updating/ Copy Table or Parts of Rows 4. Views (Virtual
More informationQuerying Data with Transact SQL
Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including
More informationRDBMS- Day 4. Grouped results Relational algebra Joins Sub queries. In today s session we will discuss about the concept of sub queries.
RDBMS- Day 4 Grouped results Relational algebra Joins Sub queries In today s session we will discuss about the concept of sub queries. Grouped results SQL - Using GROUP BY Related rows can be grouped together
More informationQuerying Data with Transact-SQL
Querying Data with Transact-SQL Course: 20761 Course Details Audience(s): IT Professional(s) Technology: Microsoft SQL Server 2016 Duration: 24 HRs. ABOUT THIS COURSE This course is designed to introduce
More informationMANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 6 Professional Program: Data Administration and Management MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) AGENDA
More informationQuerying Data with Transact-SQL
Course 20761A: Querying Data with Transact-SQL Page 1 of 5 Querying Data with Transact-SQL Course 20761A: 2 days; Instructor-Led Introduction The main purpose of this 2 day instructor led course is to
More informationDatabase Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL SQL Join Operators Join operation merges rows from two tables and returns the rows with one of the following:
More informationA subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select,
Sub queries A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select, Result of the inner query is passed to the main
More informationOracle Syllabus Course code-r10605 SQL
Oracle Syllabus Course code-r10605 SQL Writing Basic SQL SELECT Statements Basic SELECT Statement Selecting All Columns Selecting Specific Columns Writing SQL Statements Column Heading Defaults Arithmetic
More informationDatabase Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL Objectives In this chapter, you will learn: How to use the advanced SQL JOIN operator syntax About the different
More informationQuerying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)
Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761) Course Length: 3 days Course Delivery: Traditional Classroom Online Live MOC on Demand Course Overview The main purpose of this
More informationLanguage. f SQL. Larry Rockoff COURSE TECHNOLOGY. Kingdom United States. Course Technology PTR. A part ofcenqaqe Learninq
Language f SQL Larry Rockoff Course Technology PTR A part ofcenqaqe Learninq *, COURSE TECHNOLOGY!» CENGAGE Learning- Australia Brazil Japan Korea Mexico Singapore Spain United Kingdom United States '
More informationSql Server Syllabus. Overview
Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers
More information1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data
1 Writing Basic SQL SELECT Statements Objectives 1-2 Capabilities of SQL SELECT Statements 1-3 Basic SELECT Statement 1-4 Selecting All Columns 1-5 Selecting Specific Columns 1-6 Writing SQL Statements
More informationIn This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL
In This Lecture Yet More SQL Database Systems Lecture 9 Natasha Alechina Yet more SQL ORDER BY Aggregate functions and HAVING etc. For more information Connoly and Begg Chapter 5 Ullman and Widom Chapter
More informationInterview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]
Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] 1. What is DBMS? A Database Management System (DBMS) is a program that controls creation, maintenance and use
More informationTest Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke
Test Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke Link full download: https://testbankservice.com/download/test-bank-fordatabase-processing-fundamentals-design-and-implementation-13th-edition-bykroenke
More informationTeradata SQL Features Overview Version
Table of Contents Teradata SQL Features Overview Version 14.10.0 Module 0 - Introduction Course Objectives... 0-4 Course Description... 0-6 Course Content... 0-8 Module 1 - Teradata Studio Features Optimize
More informationSQL Data Query Language
SQL Data Query Language André Restivo 1 / 68 Index Introduction Selecting Data Choosing Columns Filtering Rows Set Operators Joining Tables Aggregating Data Sorting Rows Limiting Data Text Operators Nested
More informationCS 582 Database Management Systems II
Review of SQL Basics SQL overview Several parts Data-definition language (DDL): insert, delete, modify schemas Data-manipulation language (DML): insert, delete, modify tuples Integrity View definition
More information20461: Querying Microsoft SQL Server 2014 Databases
Course Outline 20461: Querying Microsoft SQL Server 2014 Databases Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions,
More informationQuerying Microsoft SQL Server 2014
Querying Microsoft SQL Server 2014 Course: 20461 Course Details Audience(s): IT Professional(s) Technology: Microsoft SQL Server 2014 Duration: 40 Hours ABOUT THIS COURSE This forty hours of instructor-led
More informationSubquery: There are basically three types of subqueries are:
Subquery: It is also known as Nested query. Sub queries are queries nested inside other queries, marked off with parentheses, and sometimes referred to as "inner" queries within "outer" queries. Subquery
More informationLab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama
The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 6 Using Subqueries and Set Operators Eng. Alaa O Shama November, 2015 Objectives:
More informationSQL - Data Query language
SQL - Data Query language Eduardo J Ruiz October 20, 2009 1 Basic Structure The simple structure for a SQL query is the following: select a1...an from t1... tr where C Where t 1... t r is a list of relations
More informationQuerying Data with Transact-SQL (20761)
Querying Data with Transact-SQL (20761) Formato do curso: Presencial e Live Training Preço: 1630 Nível: Iniciado Duração: 35 horas The main purpose of this 5 day instructor led course is to give students
More informationMTA Database Administrator Fundamentals Course
MTA Database Administrator Fundamentals Course Session 1 Section A: Database Tables Tables Representing Data with Tables SQL Server Management Studio Section B: Database Relationships Flat File Databases
More information[AVNICF-MCSASQL2012]: NICF - Microsoft Certified Solutions Associate (MCSA): SQL Server 2012
[AVNICF-MCSASQL2012]: NICF - Microsoft Certified Solutions Associate (MCSA): SQL Server 2012 Length Delivery Method : 5 Days : Instructor-led (Classroom) Course Overview Participants will learn technical
More informationOracle Database 11g: SQL and PL/SQL Fundamentals
Oracle University Contact Us: +33 (0) 1 57 60 20 81 Oracle Database 11g: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn In this course, students learn the fundamentals of SQL and PL/SQL
More informationASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql
ASSIGNMENT NO. 3 Title: Design at least 10 SQL queries for suitable database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator. Requirements:
More informationSet theory is a branch of mathematics that studies sets. Sets are a collection of objects.
Set Theory Set theory is a branch of mathematics that studies sets. Sets are a collection of objects. Often, all members of a set have similar properties, such as odd numbers less than 10 or students in
More information2) SQL includes a data definition language, a data manipulation language, and SQL/Persistent stored modules. Answer: TRUE Diff: 2 Page Ref: 36
Database Processing, 12e (Kroenke/Auer) Chapter 2: Introduction to Structured Query Language (SQL) 1) SQL stands for Standard Query Language. Diff: 1 Page Ref: 32 2) SQL includes a data definition language,
More information1.264 Lecture 7. Introduction to SQL
1.264 Lecture 7 Introduction to SQL Structured Query Language (SQL) Lecture 7: Data manipulation language (DML): SELECT, INSERT, DELETE, UPDATE Joins Lecture 8: DML continued, and data definition language
More informationSQL Part 2. Kathleen Durant PhD Northeastern University CS3200 Lesson 6
SQL Part 2 Kathleen Durant PhD Northeastern University CS3200 Lesson 6 1 Outline for today More of the SELECT command Review of the SET operations Aggregator functions GROUP BY functionality JOIN construct
More informationCOURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014
COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014 MODULE 1: INTRODUCTION TO MICROSOFT SQL SERVER 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions,
More informationSQL Queries. COSC 304 Introduction to Database Systems SQL. Example Relations. SQL and Relational Algebra. Example Relation Instances
COSC 304 Introduction to Database Systems SQL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Queries Querying with SQL is performed using a SELECT statement. The general
More informationSQL functions fit into two broad categories: Data definition language Data manipulation language
Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 7 Beginning Structured Query Language (SQL) MDM NUR RAZIA BINTI MOHD SURADI 019-3932846 razia@unisel.edu.my
More informationT-SQL Training: T-SQL for SQL Server for Developers
Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL
More informationCSC 261/461 Database Systems Lecture 5. Fall 2017
CSC 261/461 Database Systems Lecture 5 Fall 2017 MULTISET OPERATIONS IN SQL 2 UNION SELECT R.A FROM R, S WHERE R.A=S.A UNION SELECT R.A FROM R, T WHERE R.A=T.A Q 1 Q 2 r. A r. A = s. A r. A r. A = t. A}
More information2. What is the difference between UNION and UNION ALL? Write the syntax for each.
SQL Advanced Discussion Questions Solutions 1. The relational set operators UNION, INTERSECT, and MINUS work properly only if the relations are union-compatible. What does union-compatible mean, and how
More informationFull file at
David Kroenke's Database Processing: Fundamentals, Design and Implementation (10 th Edition) CHAPTER TWO INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) True-False Questions 1. SQL stands for Standard
More informationIntermediate SQL: Aggregated Data, Joins and Set Operators
Intermediate SQL: Aggregated Data, Joins and Set Operators Aggregated Data and Sorting Objectives After completing this lesson, you should be able to do the following: Identify the available group functions
More informationCS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen
CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen LECTURE 10: INTRODUCTION TO SQL FULL RELATIONAL OPERATIONS MODIFICATION LANGUAGE Union, Intersection, Differences (select
More informationDatabase Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and
More informationChapter # 7 Introduction to Structured Query Language (SQL) Part II
Chapter # 7 Introduction to Structured Query Language (SQL) Part II Updating Table Rows UPDATE Modify data in a table Basic Syntax: UPDATE tablename SET columnname = expression [, columnname = expression]
More informationObjectives. After completing this lesson, you should be able to do the following:
Objectives After completing this lesson, you should be able to do the following: Describe the types of problems that subqueries can solve Define subqueries List the types of subqueries Write single-row
More informationDatabase Management Systems,
Database Management Systems SQL Query Language (3) 1 Topics Aggregate Functions in Queries count sum max min avg Group by queries Set Operations in SQL Queries Views 2 Aggregate Functions Tables are collections
More informationBased on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO
Based on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO INSERT INTO DEPT VALUES(4, 'Prog','MO'); The result
More informationIntroduction to SQL. From Rob and Coronel (2004), Database Systems: Design, Implementation, and Management
Introduction to SQL Introduction to SQL Language to communicate with database! SQL is relatively easy to learn Basic command set has a vocabulary of less than 100 words Nonprocedural language American
More informationPreview. Advanced SQL. In this chapter, you will learn:
C6545_08 8/15/2007 16:13:3 Page 297 Advanced 8 Preview In this chapter, you will learn: About the relational set operators UNION, UNION ALL, INTERSECT, and MINUS How to use the advanced JOIN operator syntax
More informationSQL Workshop. Joins. Doug Shook
SQL Workshop Joins Doug Shook Inner Joins Joins are used to combine data from multiple tables into one result Requires the name of the column from the second table, along with a condition that defines
More informationCourse Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:
Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course: 20762C Developing SQL 2016 Databases Module 1: An Introduction to Database Development Introduction to the
More informationOracle Database 10g: Introduction to SQL
ORACLE UNIVERSITY CONTACT US: 00 9714 390 9000 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database
More informationDB2 SQL Class Outline
DB2 SQL Class Outline The Basics of SQL Introduction Finding Your Current Schema Setting Your Default SCHEMA SELECT * (All Columns) in a Table SELECT Specific Columns in a Table Commas in the Front or
More informationIntroduction to SQL Part 2 by Michael Hahsler Based on slides for CS145 Introduction to Databases (Stanford)
Introduction to SQL Part 2 by Michael Hahsler Based on slides for CS145 Introduction to Databases (Stanford) Lecture 3 Lecture Overview 1. Aggregation & GROUP BY 2. Set operators & nested queries 3. Advanced
More information1. Data Definition Language.
CSC 468 DBMS Organization Spring 2016 Project, Stage 2, Part 2 FLOPPY SQL This document specifies the version of SQL that FLOPPY must support. We provide the full description of the FLOPPY SQL syntax.
More informationEECS 647: Introduction to Database Systems
EECS 647: Introduction to Database Systems Instructor: Luke Huan Spring 2009 Stating Points A database A database management system A miniworld A data model Conceptual model Relational model 2/24/2009
More informationCOSC 304 Introduction to Database Systems SQL. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 304 Introduction to Database Systems SQL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Queries Querying with SQL is performed using a SELECT statement. The general
More information20761 Querying Data with Transact SQL
Course Overview The main purpose of this course is to give students a good understanding of the Transact-SQL language which is used by all SQL Server-related disciplines; namely, Database Administration,
More informationDatabase Systems CSE 303. Outline. Lecture 06: SQL. What is Sub-query? Sub-query in WHERE clause Subquery
Database Systems CSE 303 Lecture 06: SQL 2016 Subquery Outline What is a Subquery Subquery in WHERE clause >ALL, >ANY, >=ALL,
More informationCHAPTER 3: QUESTIONS AND ANSWERS
CHAPTER 3: QUESTIONS AND ANSWERS 1 Why do some people pronounce SQL as sequel? Because of its naming history, SQL is developed from SEQUEL language, so some people pronounce SQL as sequel. 2 Why are the
More informationWhat happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques
376a. Database Design Dept. of Computer Science Vassar College http://www.cs.vassar.edu/~cs376 Class 16 Query optimization What happens Database is given a query Query is scanned - scanner creates a list
More informationChapter 3: Introduction to SQL. Chapter 3: Introduction to SQL
Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query
More informationAfter completing this course, participants will be able to:
Querying SQL Server T h i s f i v e - d a y i n s t r u c t o r - l e d c o u r s e p r o v i d e s p a r t i c i p a n t s w i t h t h e t e c h n i c a l s k i l l s r e q u i r e d t o w r i t e b a
More informationTypes. Inner join ( Equi Joins ) Outer(left, right, full) Cross. Prepared By : - Chintan Shah & Pankti Dharwa 2
Sometimes it necessary to work with multiple tables as through they were a single entity. Then single SQL sentence can manipulate data from all the tables. Join are used to achive this. Tables are joined
More informationQuerying Data with Transact-SQL
Course Code: M20761 Vendor: Microsoft Course Overview Duration: 5 RRP: 2,177 Querying Data with Transact-SQL Overview This course is designed to introduce students to Transact-SQL. It is designed in such
More information20461: Querying Microsoft SQL Server
20461: Querying Microsoft SQL Server Length: 5 days Audience: IT Professionals Level: 300 OVERVIEW This 5 day instructor led course provides students with the technical skills required to write basic Transact
More informationTable of Contents. PDF created with FinePrint pdffactory Pro trial version
Table of Contents Course Description The SQL Course covers relational database principles and Oracle concepts, writing basic SQL statements, restricting and sorting data, and using single-row functions.
More informationSQL: Queries, Constraints, Triggers
SQL: Queries, Constraints, Triggers [R&G] Chapter 5 CS4320 1 Example Instances We will use these instances of the Sailors and Reserves relations in our examples. If the key for the Reserves relation contained
More informationQuerying Microsoft SQL Server (MOC 20461C)
Querying Microsoft SQL Server 2012-2014 (MOC 20461C) Course 21461 40 Hours This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for
More informationStructured Query Language Continued. Rose-Hulman Institute of Technology Curt Clifton
Structured Query Language Continued Rose-Hulman Institute of Technology Curt Clifton The Story Thus Far SELECT FROM WHERE SELECT * SELECT Foo AS Bar SELECT expression SELECT FROM WHERE LIKE SELECT FROM
More informationSchool of Computing, Engineering and Information Sciences University of Northumbria. Set Operations
Set Operations Aim: To understand how to do the equivalent of the UNION, DIFFERENCE and INTERSECT set operations in SQL. Outline of Session: Do some example SQL queries to learn to differentiate between
More informationAnnouncements. Joins in SQL. Joins in SQL. (Inner) joins. Joins in SQL. Introduction to Database Systems CSE 414
Announcements Introduction to Database Sstems CSE 414 Lecture 4: SQL Joins and Aggregates WQ1 due on Tuesda No late das allowed HW1 due on Tuesda Submit using script in repo WQ2 and HW2 will be out tomorrow
More informationOracle Database: Introduction to SQL Ed 2
Oracle University Contact Us: +40 21 3678820 Oracle Database: Introduction to SQL Ed 2 Duration: 5 Days What you will learn This Oracle Database 12c: Introduction to SQL training helps you write subqueries,
More informationAVANTUS TRAINING PTE LTD
[MS20461]: Querying Microsoft SQL Server 2014 Length : 5 Days Audience(s) : IT Professionals Level : 300 Technology : SQL Server Delivery Method : Instructor-led (Classroom) Course Overview This 5-day
More informationQuerying Microsoft SQL Server
20461 - Querying Microsoft SQL Server Duration: 5 Days Course Price: $2,975 Software Assurance Eligible Course Description About this course This 5-day instructor led course provides students with the
More informationPrinciples of Data Management
Principles of Data Management Alvin Lin August 2018 - December 2018 Structured Query Language Structured Query Language (SQL) was created at IBM in the 80s: SQL-86 (first standard) SQL-89 SQL-92 (what
More informationTable Joins and Indexes in SQL
Table Joins and Indexes in SQL Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, PGT CS II Shift Jaipur Introduction Sometimes we need an information
More informationOracle Database: SQL and PL/SQL Fundamentals NEW
Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the fundamentals of SQL and PL/SQL along with the
More informationReference: W3School -
Language SQL SQL Adv Reference: W3School - http://www.w3schools.com/sql/default.asp http://www.tomjewett.com/dbdesign/dbdesign.php?page=recursive.php Recursive Associations/Relationship A recursive association
More informationUNIT-IV (Relational Database Language, PL/SQL)
UNIT-IV (Relational Database Language, PL/SQL) Section-A (2 Marks) Important questions 1. Define (i) Primary Key (ii) Foreign Key (iii) unique key. (i)primary key:a primary key can consist of one or more
More informationQuerying Microsoft SQL Server 2008/2012
Querying Microsoft SQL Server 2008/2012 Course 10774A 5 Days Instructor-led, Hands-on Introduction This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL
More informationNESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)
1 NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE More Complex SQL Retrieval Queries Self-Joins Renaming Attributes and Results Grouping, Aggregation, and Group Filtering
More informationQuerying Microsoft SQL Server
Querying Microsoft SQL Server 20461D; 5 days, Instructor-led Course Description This 5-day instructor led course provides students with the technical skills required to write basic Transact SQL queries
More informationOracle Database: SQL and PL/SQL Fundamentals Ed 2
Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals
More informationCOURSE OUTLINE: Querying Microsoft SQL Server
Course Name 20461 Querying Microsoft SQL Server Course Duration 5 Days Course Structure Instructor-Led (Classroom) Course Overview This 5-day instructor led course provides students with the technical
More informationLesson 2. Data Manipulation Language
Lesson 2 Data Manipulation Language IN THIS LESSON YOU WILL LEARN To add data to the database. To remove data. To update existing data. To retrieve the information from the database that fulfil the stablished
More informationWriting Analytical Queries for Business Intelligence
MOC-55232 Writing Analytical Queries for Business Intelligence 3 Days Overview About this Microsoft SQL Server 2016 Training Course This three-day instructor led Microsoft SQL Server 2016 Training Course
More informationThis course is aimed at those who need to extract information from a relational database system.
(SQL) SQL Server Database Querying Course Description: This course is aimed at those who need to extract information from a relational database system. Although it provides an overview of relational database
More informationChapter 13: Query Optimization. Chapter 13: Query Optimization
Chapter 13: Query Optimization Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 13: Query Optimization Introduction Equivalent Relational Algebra Expressions Statistical
More informationII. Structured Query Language (SQL)
II. Structured Query Language (SQL) Lecture Topics ffl Basic concepts and operations of the relational model. ffl The relational algebra. ffl The SQL query language. CS448/648 II - 1 Basic Relational Concepts
More informationSQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5
SQL QUERIES CS121: Relational Databases Fall 2017 Lecture 5 SQL Queries 2 SQL queries use the SELECT statement General form is: SELECT A 1, A 2,... FROM r 1, r 2,... WHERE P; r i are the relations (tables)
More informationORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems
ORACLE TRAINING CURRICULUM Relational Database Fundamentals Overview of Relational Database Concepts Relational Databases and Relational Database Management Systems Normalization Oracle Introduction to
More informationQuerying Microsoft SQL Server
Querying Microsoft SQL Server Course 20461D 5 Days Instructor-led, Hands-on Course Description This 5-day instructor led course is designed for customers who are interested in learning SQL Server 2012,
More informationMicrosoft Querying Data with Transact-SQL - Performance Course
1800 ULEARN (853 276) www.ddls.com.au Microsoft 20761 - Querying Data with Transact-SQL - Performance Course Length 4 days Price $4290.00 (inc GST) Version C Overview This course is designed to introduce
More informationSQL Retrieving Data from Multiple Tables
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Database Lab (ECOM 4113) Lab 5 SQL Retrieving Data from Multiple Tables Eng. Ibraheem Lubbad An SQL JOIN clause is used
More information5. Single-row function
1. 2. Introduction Oracle 11g Oracle 11g Application Server Oracle database Relational and Object Relational Database Management system Oracle internet platform System Development Life cycle 3. Writing
More information20461D: Querying Microsoft SQL Server
20461D: Querying Microsoft SQL Server Course Details Course Code: Duration: Notes: 20461D 5 days This course syllabus should be used to determine whether the course is appropriate for the students, based
More information$99.95 per user. Writing Queries for SQL Server (2005/2008 Edition) CourseId: 160 Skill level: Run Time: 42+ hours (209 videos)
Course Description This course is a comprehensive query writing course for Microsoft SQL Server versions 2005, 2008, and 2008 R2. If you struggle with knowing the difference between an INNER and an OUTER
More informationII. Structured Query Language (SQL)
II. Structured Query Language () Lecture Topics Basic concepts and operations of the relational model. The relational algebra. The query language. CS448/648 1 Basic Relational Concepts Relating to descriptions
More information