CS2 Current Technologies Note 3 CS2Bh

Size: px
Start display at page:

Download "CS2 Current Technologies Note 3 CS2Bh"

Transcription

1 CS2 Current Technologies Note 3 SQL: Joins and Subqueries Introduction All of the queries which we saw in the previous lecture could be answered by consulting either the DEPT or the EMP table. There are, however, other queries where this is not sufficient. Let s say we would like to know all employees working in Dallas. One way to deal with this is to use two queries. First, we find out the department number of the department located in Dallas; a query on table DEPT only. Then we search for employees with the previously found department number; a query on table EMP only. Although this is a correct solution, it is somewhat cumbersome, since we need to issue two queries to answer our question. SQL provides a mechanism, the join query, which allows us to consult more than one table within a single SELECT statement. Joins: Data from Multiple Tables A join-query is a query with more than one table listed in the FROM clause. If no particular columns and rows are selected, SQL produces an output which consists of all possible concatenations of all rows of tables given in the query. For example, table EMP consists of 14 rows, with 8 columns per row, and table DEPT consists of 4 rows, with 3 columns per row. An unrestricted join of these two tables would lead to 56 rows, with each 11 columns. Such unrestricted join-queries are usually not what we want. Often, tables have a particular relation with each other. In our example, that relation is given through the department number. Through the department number we can determine information about an employee s department. To maintain this particular relation we have to specify a join-condition. The join condition for our example is specified in the WHERE clause as EMP.DEPTNO = DEPT.DEPTNO. Notice that we used a dot notation to distinguish between columns with equal names. Example 1 Which employees work in Dallas? SELECT ENAME FROM EMP, DEPT WHERE EMP.DEPTNO = DEPT.DEPTNO AND LOC = DALLAS ; 1

2 ENAME SMITH ADAMS FORD SCOTT JONES Rows in one table may be joined to rows in another by common values in corresponding columns. In the above example, the tables EMP and DEPT both have a column, DEPTNO, that contains department numbers. These columns allow you to join rows in the two tables. Suppose that you want to know where the employee named ALLEN is located. Note that the table EMP does not contain a location (LOC) column, but the table DEPT does contain a LOC column. By looking at EMP, you can see that ALLEN works in Department 30. By looking at DEPT, you can see that Department 30 is located in CHICAGO. Thus to join a row in EMP to a row in DEPT, you use the value in the DEPTNO column in each table in this case 30. But in general, the user may not know the relevant value or values that are to be used in the join. All that the user needs to know is that the general method for associating a location with an employee is to use the DEPTNO column. The SQL query is given in Example 2. Example 2 Where does ALLEN work? SELECT ENAME, LOC FROM EMP, DEPT WHERE EMP.DEPTNO = DEPT.DEPTNO AND ENAME = ALLEN ; ENAME ALLEN LOC CHICAGO Specifying Join Columns in a WHERE Clause To make a query in which rows of two tables are joined, you must specify the join columns that contain corresponding information in the two tables. Specify the tables to be joined in the FROM clause and specify the join columns in the WHERE clause. The names of the tables are separated by commas. The logical expression specifies how the tables are to be joined. It refers to the join columns in the two tables and its value is true for those combinations of rows that are to be joined. The WHERE clause may be used to specify selection conditions as well as join columns. In this case, use AND to combine the logical expressions that select rows and the logical expressions that define join conditions. 2

3 In Example 2, the first logical expression ( EMP.DEPTNO = DEPT.DEPTNO ) is the join condition and the second logical expression makes the query retrieve only those rows for which the ENAME field has the value ALLEN. (There is only one such row in this example, but there could be several employees named ALLEN in general. In this case, more than one row is retrieved.) Referring to Tables In Example 2, the DEPTNO column name is prefixed by the table name EMP or DEPT and a period. This is because both EMP and DEPT have a column named DEPTNO. It is not permitted to give two columns the same name when they are in the same table. When two columns have the same name, you must use table name prefixes to show which column you mean. If a column name is unique in the tables included in the query, you need not prefix it. Thus, for example, there is no need to prefix ENAME. Incidentally, in Example 2 the column names used in the join condition happened to be the same. In general, this need not be the case. Abbreviating a Table Name Although table name prefixes prevent ambiguity in a query, they can be tedious to enter. You can define temporary labels in the FROM clause and use them elsewhere in the query. Such temporary labels are called aliases. Note that you can use the alias in the SELECT line, even though it is only introduced in the FROM line. This is illustrated in Example 3 Example 3 Use of Aliases: SELECT D.* FROM DEPT D; Equi-Joins and Non-Equi-Joins The comparison operator used in the join condition in Example 2 was the equals sign, =. Such join queries are called equi-joins. A non-equi-join is a query that specifies some relationship other than equality between the columns. Suppose that you want to find all the employees who earn more than JONES. Example 4 illustrates how to use a non-equi-join to answer this query. Example 4 A non-equi-join query. SELECT X.ENAME, X.SAL FROM EMP X, EMP Y WHERE X.SAL > Y.SAL AND Y.ENAME = JONES ; 3

4 In Example 4, the EMP table is joined with itself using the comparison operator > (greater than). We set up the aliases X and Y for the table EMP. Each row in X is appended to JONES row in Y if the SALary is greater than JONES SALary. Note that, in general, a row in one table may be joined to many rows in another table. Thus the output can be huge compared to the size of the original tables unless some other selection condition is applied in order to reduce the number of rows. Outer Joins If a row in one of the tables does not satisfy the join condition, that row ordinarily will not appear in the query s result. In the running example, department 40 ( OPERATIONS ) has no employees. If in a query you want to display those rows from DEPT that have no matching employees, you may use the outer join operator, a plus sign enclosed in parentheses, (+). This is illustrated in Example 5. In this example, we want to list all departments which do not have any employees. Example 5 The use of the outer-join operator (+). SELECT DISTINCT DEPT.DEPTNO, DNAME, LOC FROM DEPT, EMP WHERE DEPT.DEPTNO = EMP.DEPTNO (+) AND EMPNO IS NULL; DEPTNO DNAME LOC 40 OPERATIONS BOSTON Joining a Table with Itself The use of aliases allows us to specify that we want to join a table with itself as though it were two separate copies of the same table. This is useful when you want to join one row of the table with another row of the same table. Example 6 illustrates this. Example 6 Which employees have a salary which exceeds the salary of their manager? SELECT W.ENAME, W.SAL, M.ENAME "MNAME", M.SAL "MSAL" FROM EMP W, EMP M WHERE W.MGR = M.EMPNO AND W.SAL > M.SAL; 4

5 ENAME SAL MNAME MSAL SCOTT 3000 JONES 2975 FORD 3000 JONES 2975 Example 6 treats EMP as if it were two separate tables named W and M. First, all W s rows are joined to their corresponding M rows through the join condition W.MGR = M.EMPNO. (SCOTT s MGR is 7566 and EMPNO 7566 corresponds to JONES.) In effect, this associates each employee with his/her manager. The second logical expression selects worker/manager pairs where the worker earns more than the manager (W.SAL > M.SAL). Multiple Join Conditions and Tables In the above examples, we joined two tables by examining the values in one pair or columns, one column from each table. We could specify more complex join conditions. For example, we could join two tables with two AND ed conditions requiring equality in two pairs of columns. Similarly, a query may need to join more than two tables in order to answer a query. Subqueries SQL allows us to specify queries (subqueries) in the WHERE clause of other queries. This allows us to construct very powerful complex queries which we could otherwise not express easily. Consider the query in Example 7. We answer this question using two queries: the first one determines the average salary and the second selects all jobs with a salary above this average. Example 7 Which positions are paid a higher than average salary? SELECT DISTINCT JOB FROM EMP WHERE SAL > (SELECT AVG(SAL) FROM EMP); JOB ANALYST MANAGER PRESIDENT SQL processes a subquery before it processes the main query. This is necessary since the main query uses the results of the subquery for its own processing. 5

6 Subqueries can themselves have other subqueries, and they can be as complex using all clauses we have seen above as the main query. In Example 7, the main query expects a single value to be passed back by the subquery. The SAL value is to be compared to a single number, namely the average (arithmetic mean) salary. If the subquery returns no numbers or more than one number, SQL will generate an error message. You can reference columns in the outer query from the inner query even if the same table is used in both. However, if the same table is used, the table name in the outer query may have to be prefixed by an alias to enable SQL to distinguish between the two copies of the table. Subqueries that Return a Set of Values If the subquery returns more than one value, you must specify how the returned values should be used in the WHERE clause of the outer query. You should insert one of the keywords ANY and ALL between the comparison operator and the subquery. The choice of the keyword ANY is unfortunate, as in common parlance, people often say any when they mean all. See Example 8. Example 8 Which employees earn more than ANY (i.e., at least one) employee in Department 30? SELECT SAL, ENAME FROM EMP WHERE SAL > ANY (SELECT SAL FROM EMP WHERE DEPTNO = 30) ORDER BY SAL DESC; To increase readability, SQL lets you use IN for = ANY and NOT IN for!= ALL. Subqueries that Return more than one Column When a subquery returns more than one column, you must put parentheses around the list of columns on the other side of the comparison operator. Multiple Subqueries As we already know, subqueries can be nested within subqueries. Furthermore, the WHERE clause of the outer query can contain several conditions connected by the operators AND and OR; each such condition may contain subqueries. A query may be composed of two or more queries with the operators UNION, INTERSECT and EXCEPT. 6

7 UNION returns all distinct rows returned by either subquery. INTERSECT returns all rows returned by both subqueries. EXCEPT returns all rows returned by the preceding query but not by the following query. Example 9 Display the names of all employees who have a JOB category such that there are employees in that category in both Department 20 and Department 30. SELECT JOB, ENAME, DEPTNO FROM EMP WHERE JOB IN (SELECT JOB FROM EMP WHERE DEPTNO = 20 INTERSECTION SELECT JOB FROM EMP WHERE DEPTNO = 30); Correlated Subqueries So far, the examples of subqueries that we have seen have in common that each subquery is executed once and the resulting value (or set of values) was used by the WHERE clause in the containing query. It is also possible to compose a subquery that is executed repeatedly, once for each candidate row considered for selection by the outer query. Consider the following example. Example 10 Find all employees who have a salary that is more than the average salary of the employees in their own department, and list them in department order. SELECT DEPTNO, ENAME, SAL FROM EMP X WHERE SAL > (SELECT AVG(SAL) FROM EMP WHERE X.DEPTNO = DEPTNO) ORDER BY DEPTNO; Note the table alias, X, which appears in the main query. It is used in the WHERE clause of the subquery to refer to a candidate row s value of DEPTNO. The unqualified reference to DEPTNO on the right-hand side of the = sign refers to the DEPTNO field in each row of the table. Thus, when the subquery is executed for each of the main query s candidate rows, SQL compares the value of DEPTNO in the candidate row to the value of DEPTNO in each row of the table. The subquery selects each row for which the candidate row s department number equals the selected row s department number. It returns the value of AVG(SAL) computed over the selected rows. Bear in mind the following two points concerning correlated subqueries. 7

8 A correlated subquery refers to a column selected by the main query (outside the subquery). If the subquery selects from the same table as the main query, the main query must define an alias for the table name, and the subquery must use the alias to refer to the column s values in the main query s candidate rows. Subqueries that Test for Existence The keyword EXISTS is used in the WHERE clause before a subquery. If the subquery returns at least one row, then the EXISTS (subquery) condition evaluates to true. Otherwise, it evaluates to false. Example 11 Display information about employees who have at least one other employee reporting to them. (Note that this is not the same as selecting all employees whose job is MANAGER.) SELECT JOB, ENAME, EMPNO, DEPTNO FROM EMP X WHERE EXISTS (SELECT * FROM EMP WHERE X.EMPNO = MGR) ORDER BY EMPNO; Further Reading Elmasri and Navathe, chapter 8, section 8.2 and 8.3. Ramakrishnan and Gehrke, Database Management Systems, chapter 5, section 4. 8

Displaying Data from Multiple Tables. Chapter 4

Displaying Data from Multiple Tables. Chapter 4 Displaying Data from Multiple Tables Chapter 4 1 Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using equality

More information

Displaying Data from Multiple Tables

Displaying Data from Multiple Tables Displaying Data from Multiple Tables 1 Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using eguality and

More information

Subqueries Chapter 6

Subqueries Chapter 6 Subqueries Chapter 6 Objectives After completing this lesson, you should be able to do the follovving: Describe the types of problems that subqueries can solve Define subqueries List the types of subqueries

More information

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables RDBMS Using Oracle Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture Joining Tables Multiple Table Queries Simple Joins Complex Joins Cartesian Joins Outer Joins Multi table Joins Other Multiple

More information

Chapter 1. Writing Basic. SQL Statements

Chapter 1. Writing Basic. SQL Statements Chapter 1 Writing Basic SQL Statements 1 Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL Chapter 9 Joining Data from Multiple Tables Oracle 10g: SQL Objectives Identify a Cartesian join Create an equality join using the WHERE clause Create an equality join using the JOIN keyword Create a non-equality

More information

Relational Algebra. Query Languages Review. Operators. Select (σ), Project (π), Union ( ), Difference (-), Join: Natural (*) and Theta ( )

Relational Algebra. Query Languages Review. Operators. Select (σ), Project (π), Union ( ), Difference (-), Join: Natural (*) and Theta ( ) Query Languages Review Relational Algebra SQL Set operators Union Intersection Difference Cartesian product Relational Algebra Operators Relational operators Selection Projection Join Division Douglas

More information

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB Outline Database concepts Conceptual Design Logical Design Communicating with the RDBMS 2 Some concepts Database: an

More information

Producing Readable Output with SQL*Plus

Producing Readable Output with SQL*Plus Producing Readable Output with SQL*Plus Chapter 8 Objectives After completing this lesson, you should be able to do the following: Produce queries that require an input variable Customize the SQL*Plus

More information

Aggregating Data Using Group Functions

Aggregating Data Using Group Functions Aggregating Data Using Group Functions Objectives Capter 5 After completing this lesson, you should be able to do the following: Identify the available group functions Describe the use of group functions

More information

Oracle Database 12c: Introduction to SQL Ed 1.1

Oracle Database 12c: Introduction to SQL Ed 1.1 Oracle University Contact Us: 1.800.529.0165 Oracle Database 12c: Introduction to SQL Ed 1.1 Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,

More information

SQL Introduction Chapter 7, sections 1 & 4. Introduction to SQL. Introduction to SQL. Introduction to SQL

SQL Introduction Chapter 7, sections 1 & 4. Introduction to SQL. Introduction to SQL. Introduction to SQL SQL Introduction Chapter 7, sections 1 & 4 Objectives To understand Oracle s SQL client interface Understand the difference between commands to the interface and SQL language. To understand the Oracle

More information

Database CIS 340. lab#6. I.Arwa Najdi a_najdi1988@yahoo.com

Database CIS 340. lab#6. I.Arwa Najdi a_najdi1988@yahoo.com Database CIS 340 lab#6 I.Arwa Najdi a_najdi1988@yahoo.com Outlines Obtaining Data from Multiple Tables (Join) Equijoins= inner join natural join Creating Joins with the USING Clause Creating Joins with

More information

Oracle SQL. Course Summary. Duration. Objectives

Oracle SQL. Course Summary. Duration. Objectives Oracle SQL Course Summary Identify the major structural components of the Oracle Database 11g Create reports of aggregated data Write SELECT statements that include queries Retrieve row and column data

More information

Displaying Data from Multiple Tables

Displaying Data from Multiple Tables 4 Displaying Data from Multiple Tables Copyright Oracle Corporation, 2001. All rights reserved. Schedule: Timing Topic 55 minutes Lecture 55 minutes Practice 110 minutes Total Objectives After completing

More information

Writing Control Structures

Writing Control Structures Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

More information

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff D80198GC10 Oracle Database 12c SQL and Fundamentals Summary Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff Level Professional Delivery Method Instructor-led

More information

Unit 3. Retrieving Data from Multiple Tables

Unit 3. Retrieving Data from Multiple Tables Unit 3. Retrieving Data from Multiple Tables What This Unit Is About How to retrieve columns from more than one table or view. What You Should Be Able to Do Retrieve data from more than one table or view.

More information

Oracle/SQL Tutorial 1

Oracle/SQL Tutorial 1 Oracle/SQL Tutorial 1 Michael Gertz Database and Information Systems Group Department of Computer Science University of California, Davis gertz@cs.ucdavis.edu http://www.db.cs.ucdavis.edu This Oracle/SQL

More information

3.GETTING STARTED WITH ORACLE8i

3.GETTING STARTED WITH ORACLE8i Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer

More information

Displaying Data from Multiple Tables. Copyright 2006, Oracle. All rights reserved.

Displaying Data from Multiple Tables. Copyright 2006, Oracle. All rights reserved. Displaying Data from Multiple Tables Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using equijoins and

More information

Retrieval: Multiple Tables and Aggregation

Retrieval: Multiple Tables and Aggregation 4487CH08.qxd 11/24/04 10:15 AM Page 191 CHAPTER 8 Retrieval: Multiple Tables and Aggregation This chapter resumes the discussion of the retrieval possibilities of the SQL language. It is a logical continuation

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING DR.NAVALAR NEDUNCHEZHIAYN COLLEGE OF ENGINEERING, THOLUDUR-606303, CUDDALORE DIST.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING DR.NAVALAR NEDUNCHEZHIAYN COLLEGE OF ENGINEERING, THOLUDUR-606303, CUDDALORE DIST. CS2258-DATABASE MANAGEMENT SYSTEM LABORATORY LABORATORY MANUAL FOR IV SEMESTER B. E / CSE & IT (FOR PRIVATE CIRCULATION ONLY) ACADEMIC YEAR: 2013 2014 (EVEN) ANNA UNIVERSITY, CHENNAI DEPARTMENT OF COMPUTER

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along

More information

Relational Database: Additional Operations on Relations; SQL

Relational Database: Additional Operations on Relations; SQL Relational Database: Additional Operations on Relations; SQL Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin Overview The course packet

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: +966 12 739 894 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training is designed to

More information

VARRAY AND NESTED TABLE

VARRAY AND NESTED TABLE Oracle For Beginners Page : 1 Chapter 23 VARRAY AND NESTED TABLE What is a collection? What is a VARRAY? Using VARRAY Nested Table Using DML commands with Nested Table Collection methods What is a collection?

More information

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.

More information

DECLARATION SECTION. BODY STATEMENTS... Required

DECLARATION SECTION. BODY STATEMENTS... Required 1 EXCEPTION DECLARATION SECTION Optional BODY STATEMENTS... Required STATEMENTS Optional The above Construction is called PL/SQL BLOCK DATATYPES 2 Binary Integer (-2 **31-1,2**31+1) signed integer fastest

More information

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

MOC 20461C: Querying Microsoft SQL Server. Course Overview

MOC 20461C: Querying Microsoft SQL Server. Course Overview MOC 20461C: Querying Microsoft SQL Server Course Overview This course provides students with the knowledge and skills to query Microsoft SQL Server. Students will learn about T-SQL querying, SQL Server

More information

Define terms Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins

Define terms Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins Chapter 7 Advanced SQL 1 Define terms Objectives Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins 2 Nested Queries (Subqueries)

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle University Contact Us: + 38516306373 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

More information

Oracle 10g PL/SQL Training

Oracle 10g PL/SQL Training Oracle 10g PL/SQL Training Course Number: ORCL PS01 Length: 3 Day(s) Certification Exam This course will help you prepare for the following exams: 1Z0 042 1Z0 043 Course Overview PL/SQL is Oracle's Procedural

More information

Introduction to SQL: Data Retrieving

Introduction to SQL: Data Retrieving Introduction to SQL: Data Retrieving Ruslan Fomkin Databasdesign för Ingenjörer 1056F Structured Query Language (SQL) History: SEQUEL (Structured English QUery Language), earlier 70 s, IBM Research SQL

More information

Introduction to Querying & Reporting with SQL Server

Introduction to Querying & Reporting with SQL Server 1800 ULEARN (853 276) www.ddls.com.au Introduction to Querying & Reporting with SQL Server Length 5 days Price $4169.00 (inc GST) Overview This five-day instructor led course provides students with the

More information

Objectives. Oracle SQL and SQL*PLus. Database Objects. What is a Sequence?

Objectives. Oracle SQL and SQL*PLus. Database Objects. What is a Sequence? Oracle SQL and SQL*PLus Lesson 12: Other Database Objects Objectives After completing this lesson, you should be able to do the following: Describe some database objects and their uses Create, maintain,

More information

1 Structured Query Language: Again. 2 Joining Tables

1 Structured Query Language: Again. 2 Joining Tables 1 Structured Query Language: Again So far we ve only seen the basic features of SQL. More often than not, you can get away with just using the basic SELECT, INSERT, UPDATE, or DELETE statements. Sometimes

More information

Performing Queries Using PROC SQL (1)

Performing Queries Using PROC SQL (1) SAS SQL Contents Performing queries using PROC SQL Performing advanced queries using PROC SQL Combining tables horizontally using PROC SQL Combining tables vertically using PROC SQL 2 Performing Queries

More information

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours Course 20461C: Querying Microsoft SQL Server Duration: 35 hours About this Course This course is the foundation for all SQL Server-related disciplines; namely, Database Administration, Database Development

More information

ICAB4136B Use structured query language to create database structures and manipulate data

ICAB4136B Use structured query language to create database structures and manipulate data ICAB4136B Use structured query language to create database structures and manipulate data Release: 1 ICAB4136B Use structured query language to create database structures and manipulate data Modification

More information

Structured Query Language (SQL)

Structured Query Language (SQL) Objectives of SQL Structured Query Language (SQL) o Ideally, database language should allow user to: create the database and relation structures; perform insertion, modification, deletion of data from

More information

Course ID#: 1401-801-14-W 35 Hrs. Course Content

Course ID#: 1401-801-14-W 35 Hrs. Course Content Course Content Course Description: This 5-day instructor led course provides students with the technical skills required to write basic Transact- SQL queries for Microsoft SQL Server 2014. This course

More information

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using equijoins and

More information

Netezza SQL Class Outline

Netezza SQL Class Outline Netezza SQL Class Outline CoffingDW education has been customized for every customer for the past 20 years. Our classes can be taught either on site or remotely via the internet. Education Contact: John

More information

Querying Microsoft SQL Server 20461C; 5 days

Querying Microsoft SQL Server 20461C; 5 days Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc Querying Microsoft SQL Server 20461C; 5 days Course Description This 5-day

More information

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server Course 20461C: Querying Microsoft SQL Server Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions, tools used

More information

Querying Microsoft SQL Server Course M20461 5 Day(s) 30:00 Hours

Querying Microsoft SQL Server Course M20461 5 Day(s) 30:00 Hours Área de formação Plataforma e Tecnologias de Informação Querying Microsoft SQL Introduction This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL

More information

Where? Originating Table Employees Departments

Where? Originating Table Employees Departments JOINS: To determine an employee s department name, you compare the value in the DEPARTMENT_ID column in the EMPLOYEES table with the DEPARTMENT_ID values in the DEPARTMENTS table. The relationship between

More information

Querying Microsoft SQL Server 2012

Querying Microsoft SQL Server 2012 Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Language(s): English Audience(s): IT Professionals Level: 200 Technology: Microsoft SQL Server 2012 Type: Course Delivery Method: Instructor-led

More information

SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6

SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6 SUBQUERIES AND VIEWS CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6 String Comparisons and GROUP BY 2! Last time, introduced many advanced features of SQL, including GROUP BY! Recall:

More information

Course 10774A: Querying Microsoft SQL Server 2012

Course 10774A: Querying Microsoft SQL Server 2012 Course 10774A: Querying Microsoft SQL Server 2012 About this Course This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft

More information

Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals

Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals Overview About this Course Level: 200 Technology: Microsoft SQL

More information

Using Temporary Tables to Improve Performance for SQL Data Services

Using Temporary Tables to Improve Performance for SQL Data Services Using Temporary Tables to Improve Performance for SQL Data Services 2014- Informatica Corporation. No part of this document may be reproduced or transmitted in any form, by any means (electronic, photocopying,

More information

Information Systems SQL. Nikolaj Popov

Information Systems SQL. Nikolaj Popov Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria popov@risc.uni-linz.ac.at Outline SQL Table Creation Populating and Modifying

More information

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio Querying Microsoft SQL Server 2012 Microsoft Course 10774 This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server

More information

Lab # 5. Retreiving Data from Multiple Tables. Eng. Alaa O Shama

Lab # 5. Retreiving Data from Multiple Tables. Eng. Alaa O Shama The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 5 Retreiving Data from Multiple Tables Eng. Alaa O Shama November, 2015 Objectives:

More information

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Physical Design. Phases of database design. Physical design: Inputs.

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Physical Design. Phases of database design. Physical design: Inputs. Phases of database design Application requirements Conceptual design Database Management Systems Conceptual schema Logical design ER or UML Physical Design Relational tables Logical schema Physical design

More information

Effective Use of SQL in SAS Programming

Effective Use of SQL in SAS Programming INTRODUCTION Effective Use of SQL in SAS Programming Yi Zhao Merck & Co. Inc., Upper Gwynedd, Pennsylvania Structured Query Language (SQL) is a data manipulation tool of which many SAS programmers are

More information

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems CSC 74 Database Management Systems Topic #0: SQL Part A: Data Definition Language (DDL) Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning Schema and Catalog Schema A collection

More information

SQL Nested & Complex Queries. CS 377: Database Systems

SQL Nested & Complex Queries. CS 377: Database Systems SQL Nested & Complex Queries CS 377: Database Systems Recap: Basic SQL Retrieval Query A SQL query can consist of several clauses, but only SELECT and FROM are mandatory SELECT FROM

More information

There are five fields or columns, with names and types as shown above.

There are five fields or columns, with names and types as shown above. 3 THE RELATIONAL MODEL Exercise 3.1 Define the following terms: relation schema, relational database schema, domain, attribute, attribute domain, relation instance, relation cardinality, andrelation degree.

More information

SQL SELECT Query: Intermediate

SQL SELECT Query: Intermediate SQL SELECT Query: Intermediate IT 4153 Advanced Database J.G. Zheng Spring 2012 Overview SQL Select Expression Alias revisit Aggregate functions - complete Table join - complete Sub-query in where Limiting

More information

David L. Fuston, dfuston@vlamis.com Vlamis Software Solutions, Inc., www.vlamis.com

David L. Fuston, dfuston@vlamis.com Vlamis Software Solutions, Inc., www.vlamis.com Data Warehouse and E-Business Intelligence ORACLE S SQL ANALYTIC FUNCTIONS IN 8i AND 9i David L. Fuston, dfuston@vlamis.com, www.vlamis.com INTRODUCTION The SQL language has traditionally provided little

More information

Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables. Lesson C Objectives. Joining Multiple Tables

Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables. Lesson C Objectives. Joining Multiple Tables Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables Wednesay 9/24/2014 Abdou Illia MIS 4200 - Fall 2014 Lesson C Objectives After completing this lesson, you should be able

More information

The Entity-Relationship Model

The Entity-Relationship Model The Entity-Relationship Model 221 After completing this chapter, you should be able to explain the three phases of database design, Why are multiple phases useful? evaluate the significance of the Entity-Relationship

More information

Data Models and Database Management Systems (DBMSs) Dr. Philip Cannata

Data Models and Database Management Systems (DBMSs) Dr. Philip Cannata Data Models and Database Management Systems (DBMSs) Dr. Philip Cannata 1 Data Models in the 1960s, 1970s, and 1980s Hierarchical Network (Graph) Relational Schema (Model) - first 1956 Vern Watts was IMS's

More information

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database

More information

Oracle Database 11g SQL

Oracle Database 11g SQL AO3 - Version: 2 19 June 2016 Oracle Database 11g SQL Oracle Database 11g SQL AO3 - Version: 2 3 days Course Description: This course provides the essential SQL skills that allow developers to write queries

More information

Maximizing Materialized Views

Maximizing Materialized Views Maximizing Materialized Views John Jay King King Training Resources john@kingtraining.com Download this paper and code examples from: http://www.kingtraining.com 1 Session Objectives Learn how to create

More information

D B M G Data Base and Data Mining Group of Politecnico di Torino

D B M G Data Base and Data Mining Group of Politecnico di Torino Politecnico di Torino Database Management System Oracle Hints Data Base and Data Mining Group of Politecnico di Torino Tania Cerquitelli Computer Engineering, 2014-2015, slides by Tania Cerquitelli and

More information

MOC 20461 QUERYING MICROSOFT SQL SERVER

MOC 20461 QUERYING MICROSOFT SQL SERVER ONE STEP AHEAD. MOC 20461 QUERYING MICROSOFT SQL SERVER Length: 5 days Level: 300 Technology: Microsoft SQL Server Delivery Method: Instructor-led (classroom) COURSE OUTLINE Module 1: Introduction to Microsoft

More information

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query Objectives The objective of this lab is to learn the query language of SQL. Outcomes After completing this Lab,

More information

SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach TRAINING & REFERENCE murach's SQL Server 2012 for developers Bryan Syverson Joel Murach Mike Murach & Associates, Inc. 4340 N. Knoll Ave. Fresno, CA 93722 www.murach.com murachbooks@murach.com Expanded

More information

ETL TESTING TRAINING

ETL TESTING TRAINING ETL TESTING TRAINING DURATION 35hrs AVAILABLE BATCHES WEEKDAYS (6.30AM TO 7.30AM) & WEEKENDS (6.30pm TO 8pm) MODE OF TRAINING AVAILABLE ONLINE INSTRUCTOR LED CLASSROOM TRAINING (MARATHAHALLI, BANGALORE)

More information

Consulting. Personal Attention, Expert Assistance

Consulting. Personal Attention, Expert Assistance Consulting Personal Attention, Expert Assistance 1 Writing Better SQL Making your scripts more: Readable, Portable, & Easily Changed 2006 Alpha-G Consulting, LLC All rights reserved. 2 Before Spending

More information

SQL Programming. Student Workbook

SQL Programming. Student Workbook SQL Programming Student Workbook 2 SQL Programming SQL Programming Published by itcourseware, Inc., 7245 South Havana Street, Suite 100, Englewood, CO 80112 Contributing Authors: Denise Geller, Rob Roselius,

More information

Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25)

Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25) Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25) Which three statements inserts a row into the table? A. INSERT INTO employees

More information

Introduction to Microsoft Jet SQL

Introduction to Microsoft Jet SQL Introduction to Microsoft Jet SQL Microsoft Jet SQL is a relational database language based on the SQL 1989 standard of the American Standards Institute (ANSI). Microsoft Jet SQL contains two kinds of

More information

SQL Server. 1. What is RDBMS?

SQL Server. 1. What is RDBMS? SQL Server 1. What is RDBMS? Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained

More information

Conversion Functions

Conversion Functions Conversion Functions Conversion functions convert a value from one datatype to another. Generally, the form of the function names follows the convention datatype TO datatype. The first datatype is the

More information

AN INTRODUCTION TO THE SQL PROCEDURE Chris Yindra, C. Y. Associates

AN INTRODUCTION TO THE SQL PROCEDURE Chris Yindra, C. Y. Associates AN INTRODUCTION TO THE SQL PROCEDURE Chris Yindra, C Y Associates Abstract This tutorial will introduce the SQL (Structured Query Language) procedure through a series of simple examples We will initially

More information

Instant SQL Programming

Instant SQL Programming Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions

More information

SQL*Plus User s Guide and Reference

SQL*Plus User s Guide and Reference SQL*Plus User s Guide and Reference Release 8.0 Part No. A53717 01 Enabling the Information Age SQL*Plus User s Guide and Reference, Release 8.0 Part No. A53717 01 Copyright 1997 Oracle Corporation All

More information

Mini User's Guide for SQL*Plus T. J. Teorey

Mini User's Guide for SQL*Plus T. J. Teorey Mini User's Guide for SQL*Plus T. J. Teorey Table of Contents Oracle/logging-in 1 Nested subqueries 5 SQL create table/naming rules 2 Complex functions 6 Update commands 3 Save a query/perm table 6 Select

More information

Advanced Query for Query Developers

Advanced Query for Query Developers for Developers This is a training guide to step you through the advanced functions of in NUFinancials. is an ad-hoc reporting tool that allows you to retrieve data that is stored in the NUFinancials application.

More information

Querying Microsoft SQL Server 2012

Querying Microsoft SQL Server 2012 Querying Microsoft SQL Server 2012 MOC 10774 About this Course This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL

More information

IT2305 Database Systems I (Compulsory)

IT2305 Database Systems I (Compulsory) Database Systems I (Compulsory) INTRODUCTION This is one of the 4 modules designed for Semester 2 of Bachelor of Information Technology Degree program. CREDITS: 04 LEARNING OUTCOMES On completion of this

More information

Training Guide. PL/SQL for Beginners. Workbook

Training Guide. PL/SQL for Beginners. Workbook An Training Guide PL/SQL for Beginners Workbook Workbook This workbook should be worked through with the associated Training Guide, PL/SQL for Beginners. Each section of the workbook corresponds to a section

More information

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL Ben B. Kim, Seattle University, bkim@seattleu.edu ABSTRACT The entity-relationship (ER model is clearly

More information

2. DECODE Function, CASE Expression

2. DECODE Function, CASE Expression DECODE Function, CASE Expression 2.1 2. DECODE Function, CASE Expression Introduction to DECODE DECODE Examples Contrast with 9i Case Statement CASE Examples CASE Histograms SKILLBUILDERS DECODE Function,

More information

Objectives of SQL. Terminology for Relational Model. Introduction to SQL

Objectives of SQL. Terminology for Relational Model. Introduction to SQL Karlstad University Department of Information Systems Adapted for a textbook by Date C. J. An Introduction to Database Systems Pearson Addison Wesley, 2004 Introduction to SQL Remigijus GUSTAS Phone: +46-54

More information

ORACLE 10g Lab Guide

ORACLE 10g Lab Guide A supplement to: Database Systems: Design, Implementation and Management (International Edition) Rob, Coronel & Crockett (ISBN: 9781844807321) Table of Contents Lab Title Page 1 Introduction to ORACLE

More information

Access to Relational Databases Using SAS. Frederick Pratter, Destiny Corp.

Access to Relational Databases Using SAS. Frederick Pratter, Destiny Corp. Paper TF-21 Access to Relational Databases Using SAS ABSTRACT Frederick Pratter, Destiny Corp. SAS software currently provides many of the features of a database management system, including database views

More information

Lecture 4: More SQL and Relational Algebra

Lecture 4: More SQL and Relational Algebra CPSC 421 Database Management Systems Lecture 4: More SQL and Relational Algebra * Some material adapted from R. Ramakrishnan, L. Delcambre, and B. Ludaescher Today s Agenda Go over last week s quiz New

More information

Chapter 1 Overview of the SQL Procedure

Chapter 1 Overview of the SQL Procedure Chapter 1 Overview of the SQL Procedure 1.1 Features of PROC SQL...1-3 1.2 Selecting Columns and Rows...1-6 1.3 Presenting and Summarizing Data...1-17 1.4 Joining Tables...1-27 1-2 Chapter 1 Overview of

More information

Data Tool Platform SQL Development Tools

Data Tool Platform SQL Development Tools Data Tool Platform SQL Development Tools ekapner Contents Setting SQL Development Preferences...5 Execution Plan View Options Preferences...5 General Preferences...5 Label Decorations Preferences...6

More information

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

Chapter 9, More SQL: Assertions, Views, and Programming Techniques Chapter 9, More SQL: Assertions, Views, and Programming Techniques 9.2 Embedded SQL SQL statements can be embedded in a general purpose programming language, such as C, C++, COBOL,... 9.2.1 Retrieving

More information