Lecture10: Data Manipulation in SQL, Advanced SQL queries

Size: px
Start display at page:

Download "Lecture10: Data Manipulation in SQL, Advanced SQL queries"

Transcription

1 IS220 / IS422 : Database Fundamentals : Data Manipulation in SQL, Advanced SQL queries Ref. Chapter5 Prepared by L. Nouf Almujally & Aisha AlArfaj College of Computer and Information Sciences - Information Systems Dept. 1

2 The Process of Database Design Real World Domain Conceptual model (ERD) Relational Data Model Create schema (DDL) Load Data (DML) 2

3 Sample Data in Customer Table custno custname custst custcity age 1 C1 Olaya St Jeddah 20 2 C2 Mains St Riyadh 30 3 C3 Mains Rd Riyadh 25 4 C4 Mains Rd Dammam 5 C5 Mains Rd Riyadh 3

4 Sample Data in Product Table prodno prodname proddes price 100 P0 Food P1 healthy food P P3 self_raising flour,80%wheat P4 network 80x 300 4

5 Sample Data in Orders Table ordno orddate custno prodno quantity 1 01-jan jan jan jan jan mar

6 EMPLOYEE Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E2 Daniel Hodges D E3 Shaskia Ramanthan D E4 Graham Burke D E5 Annie Nguyen D DEPARTMENT Dept Number Dept Name Location Mail Number D1 Computer Science Bundoora 39 D2 Information Science Bendigo 30 D3 Physics Bundoora 37 D4 Chemistry Bendigo 35 6

7 Sample Data Table in orders Customer ( Example 3) Table O_Id OrderDate OrderPrice Customer /11/ Nora /10/ Sara /09/ Nora /09/ Nora /08/ Yara /10/ Sara 7

8 Table names and Column names Table name can be prefixed with the owner name. eg, if table product is owned by user John, you can use SELECT * FROM John.product; Column names can be prefixed with table name, SELECT product.prodno FROM product; 8

9 Alias SQL aliases are used to temporarily rename a table or a column heading. Syntax for Columns SELECT column_name AS alias_name FROM table_name; Syntax for Tables SELECT column_name(s) FROM table_name [AS] alias_name; 9

10 Alias ( important note ) Columns Alias: For example, you might wish to know how much is the combined total salary of all employees whose salary is above $25,000 / year. SELECT SUM(salary) AS "Total Salary" FROM employees WHERE salary > 25000; In this example, we've aliased the sum(salary) field as "Total Salary". As a result, "Total Salary" will display as the field name when the result set is returned. Table Alias: SELECT o.orderid, o.orderdate FROM Orders AS o; 10

11 Exercise create table count_null ( a number, b number ); Output : insert into count_null values ( 1, 5); insert into count_null values ( null, 7); insert into count_null values ( null, null); insert into count_null values ( 8, 2); select count(a) as "count_a_not_null", count(b) as "count_b_not_null", count(*) as "count_all from count_null; 11

12 JOIN 12

13 JOIN Often two or more tables are needed at the same time to find all required data These tables must be "joined" together The formal JOIN basically, computes a new table from those to be joined the new table contains data in the matching rows of the individual tables. 13

14 Types of JOIN types of JOIN:. INNER JOIN: Return rows when there is at least one match in both tables LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table Full Outer Joins : retains rows that are unmatched in both the tables. NOTE: In all the above outer joins, the displayed unmatched columns are filled with NULLS. 14

15 Types of JOIN 15

16 SQL Examples of Joins ( 1) Simple Join SELECT E.firstName, E.lastName, D.deptName FROM EMPLOYEE E, DEPARTMENT D WHERE E.deptNumber = D.deptNumber; Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E2 Daniel Hodges D E3 Shaskia Ramanthan D E4 Graham Burke D E5 Annie Nguyen D Dept Number Dept Name Location Mail Number D1 Computer Science Bundoora 39 D2 Information Science Bendigo 30 D3 Physics Bundoora 37 D4 Chemistry Bendigo 35 16

17 This is the result from the matching Employee N First Name Last Name Salary Dept Number Dept Number Dept Name Location ail Numbe E1 Mandy Smith D1 D1 Computer Science Bundoora 39 E2 Daniel Hodges D2 D2 Information Science Bendigo 30 E3 Shaskia Ramanthan D2 D2 Information Science Bundoora 37 E4 Graham Burke D1 D1 Computer Science Bundoora 39 E5 Annie Nguyen D1 D1 Computer Science Bundoora 39 This is the final result: FIRSTNAME LASTNAME DEPTNAME Mandy Smith computer science Annie Nguyen computer science Graham Burke Computer Science Shaskia Ramanthan Information Science Daniel Hodges Information Science 17

18 SQL Examples of Joins ( 2 ) Joining more than two tables SELECT E.firstName, E.lastName, P.projTitle FROM EMPLOYEE E, WORKS_ON W, PROJECT P WHERE E.employeeNo = W.employeeNo AND W.projNo = P.projNo; WORKS_ON Employee No. ProjNo E1 1 E4 1 E5 2 E2 3 E3 1 ProjNo Project Title 1 Project A 2 Project B 3 Project C PROJECT EMPLOYEE Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E4 Graham Burke D E5 Annie Nguyen D E2 Daniel Hodges D E3 Shaskia Ramanthan D FIRSTNAME LASTNAME PROJTITLE Mandy Smith Project A Graham Burke Project A Annie Nguyen Project B Daniel Hodges Project C Shaskia Ramanthan Project A 18

19 SQL Examples of Joins ( 3 ) List customers (by customer number, name and address) who have ordered the product 100. SELECT c.custno, custname, custst, custcity FROM customer c, orders o WHERE c.custno=o.custno AND prodno=100; CUSTNO CUSTNAME CUSTST CUSTCITY C1 Olaya St Jeddah 2 C2 Mains St Riyadh 3 C3 Mains Rd Riyadh custn o custn ame custst custcity age 1 C1 Olaya St Jeddah 20 2 C2 Mains St Riyadh 30 3 C3 Mains Rd Riyadh 25 4 C4 Mains Rd Dammam 5 C5 Mains Rd Riyadh ordno orddate custno prodno quantity 1 01-jan jan jan jan jan mar

20 SQL Examples of Joins ( 4 ) Find the total price of the products ordered by customer 1. SELECT sum(price*quantity) FROM orders, product WHERE orders.prodno = product.prodno AND custno = 1; SUM(PRICE*QUANTITY) prod No prodn ame proddes price 100 P0 Food P1 healthy food P P3 self_raising flour,80%wheat P4 network 80x 300 ordno orddate custno prodn o 1 01-jan jan jan jan jan quant ity 6 06-mar

21 Outer Joins in Oracle SQL Put an (+) on the potentially deficient side, ie the side where nulls may be added The (+) operator is placed in the join condition next to the table that is allowed to have NULL values. Example (Left Outer Join) : List all customers, and the products ordered if they have ordered some products. SELECT c.custno, o.prodno, quantity FROM customer c, orders o WHERE c.custno = o.custno (+); Note: a table may be outer joined with only one other table. Which table column to use is important, eg, in above example, do not use o.custno in place of c.custno in the SELECT list. 21

22 1) Inner Join SQL Example SELECT Student_Name, Advisor_Name FROM Students, Advisors WHERE Students.Advisor_ID= Advisors.Advisor_ID; 22

23 2) Left Outer Join SQL Example SELECT Student_Name, Advisor_Name FROM Students, Advisors WHERE Students.Advisor_ID= Advisors.Advisor_ID (+); 23

24 3) Right Outer Join SQL Example SELECT Student_Name, Advisor_Name FROM Students, Advisors WHERE Students.Advisor_ID(+)= Advisors.Advisor_ID ; Student_Name Advisor_Name Student_1 advisor 1 Student_5 advisor 3 Student_7 advisor 3 Student_9 advisor 1 24 Student_10 advisor 3 null Advisor 5

25 4) Full Outer Join SQL Example SELECT Student_Name, Advisor_Name FROM Students, Advisors WHERE Students.Advisor_ID (+) = Advisors.Advisor_ID (+) ; 25

26 26

27 Nested Queries (1) Query results are tables, which can also be queried. SELECT * FROM (SELECT prodno, sum(quantity) AS sum FROM orders GROUP BY prodno) WHERE sum>10; Equivalent to PRODNO SUM SELECT prodno, sum(quantity) as sum FROM orders GROUP BY prodno HAVING sum(quantity)>10; PRODNO SUM The inner query is referred to as a subquery 27

28 prodno prodname proddes price Nested Queries (2) 100 P0 Food P1 healthy food P P3 self_raising flour,80%wheat P4 network 80x 300 If the query result is a single value, it can be treated as a value, and be compared with other values. Subquery with equality ( <, >) : Example: Find products with price more than average SELECT prodno, price FROM product WHERE price > (SELECT AVG(price) FROM product); AVG(PRICE) 200 PRODNO PRICE

29 Subquery Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E2 Daniel Hodges D E3 Shaskia Ramanthan D E4 Graham Burke D E5 Annie Nguyen D Subquery with equality (=) : Give a list with first and last names of employees who work in the department with mail number = 39 SELECT firstname, lastname FROM EMPLOYEE Dept Number Dept Name Location Mail Number D1 Computer Science Bundoora 39 D2 Information Science Bendigo 30 D3 Physics Bundoora 37 D4 Chemistry Bendigo 35 WHERE deptnumber =(SELECT deptnumber FROM DEPARTMENT WHERE mailnumber = 39); FIRSTNAME LASTNAME mandy smith graham burke Annie nguyen DEPTNUMBER D1 29

30 Subquery Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E2 Daniel Hodges D E3 Shaskia Ramanthan D E4 Graham Burke D E5 Annie Nguyen D Subquery with aggregate function: Give a list with first, last names and salary of employees whose salary is greater than average salary for all employees. SELECT firstname, lastname, salary FROM EMPLOYEE Dept Number Dept Name Location Mail Number D1 Computer Science Bundoora 39 D2 Information Science Bendigo 30 D3 Physics Bundoora 37 D4 Chemistry Bendigo 35 WHERE salary > (SELECT avg(salary) FROM EMPLOYEE); AVG(SALARY) FIRSTNAME LASTNAME SALARY Shaskia Ramanthan Annie Nguyen

31 Subquery Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E2 Daniel Hodges D E3 Shaskia Ramanthan D E4 Graham Burke D E5 Annie Nguyen D Nested Subquery (use of IN): Give a list with first, last names of employees whose departments are located in Bundoora. SELECT firstname, lastname FROM EMPLOYEE WHERE deptnumber IN (SELECT deptnumber FIRSTNAME LASTNAME Annie nguyen graham burke mandy smith Dept Number Dept Name Location Mail Number D1 Computer Science Bundoora 39 D2 Information Science Bendigo 30 D3 Physics Bundoora 37 D4 Chemistry Bendigo 35 FROM DEPARTMENT WHERE lo atio = Bundoora ; deptnumber D1 D3 31

32 Subquery List the products ordered by customers living in Riyadh. SELECT prodno FROM orders WHERE custno IN (SELECT custno FROM customer WHERE custcity = Riyadh ; - This query is equivalent to custno SELECT prodno FROM orders o, customer c WHERE o.custno =c.custno AND custcity = Riyadh'; PRODNO

33 33

34 Queries using EXISTS or NOT EXISTS Queries using EXISTS Designed for use only with subqueries EXISTS return true if there exists at least one row in the result table returned by the subquery, it is false if the subquery returns an empty result table. Syntax SELECT column_name FROM table_name WHERE EXISTS NOT EXISTS ( subquery ); 34

35 Queries using EXISTS or NOT EXISTS Example SELECT firstname, lastname FROM EMPLOYEE E FIRSTNAME LASTNAME Shaskia Ramanthan Daniel Hodges WHERE EXISTS (SELECT * FROM DEPARTMENT D WHERE E.deptNumber = D.deptNumber AND D.location = Bendigo ); Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E2 Daniel Hodges D E3 Shaskia Ramanthan D E4 Graham Burke D E5 Annie Nguyen D Dept Number Dept Name Location Mail Number D1 Computer Science Bundoora 39 D2 Information Science Bendigo 30 D3 Physics Bundoora 37 D4 Chemistry Bendigo 35 35

36 Example. EXISTS custno custname custst custcity age 1 C1 Olaya St Jeddah 20 2 C2 Mains St Riyadh 30 3 C3 Mains Rd Riyadh 25 4 C4 Mains Rd Dammam 5 C5 Mains Rd Riyadh Find all customers who have ordered some products. SELECT * FROM customer c WHERE exists (SELECT * FROM orders o WHERE o.custno =c.custno); ordno orddate custn o prodno 1 01-jan jan jan jan jan mar CUSTNO CUNAME CUSTST CUSTCITY AGE C1 Olaya St Jeddah 20 2 C2 Mains St Riyadh 30 3 C3 Mains Rd Riyadh 25 If the subquery is not empty, then the exists condition is true. quant ity 36

37 Example. NOT EXISTS custno custname custst custcity age 1 C1 Olaya St Jeddah 20 2 C2 Mains St Riyadh 30 3 C3 Mains Rd Riyadh 25 4 C4 Mains Rd Dammam Find all customers such that no order made by them has a quantity less than 2. SELECT * FROM customer c WHERE NOT EXISTS (SELECT * FROM orders o WHERE o.custno = c.custno AND quantity <2); CUSTNO CUTNAME CUSTST CUSTCITY AGE C5 Mains Rd Riyadh 4 C4 Mains Rd Dammam 3 C3 Mains Rd Riyadh 25 5 C5 Mains Rd Riyadh ordno orddate custno prodno quant ity 1 01-jan jan jan jan jan mar

38 38

39 UNION The UNION operator is used to combine the result-set of two or more SELECT statements. Notice that each SELECT statement within the UNION must 1. have the same number of columns. 2. The columns must also have similar data types. 3. the columns in each SELECT statement must be in the same order. Combines the results of two SELECT statements into one result set, and then eliminates any duplicate rows from that result set. SQL UNION Syntax SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2 39

40 UNION Note: The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL. UNION ALL Combines the results of two SELECT statements into one result set. SQL UNION ALL Syntax SELECT column_name(s) FROM table_name1 UNION ALL SELECT column_name(s) FROM table_name2 40

41 UNION Example 1 "Employees_Norway" E_ID E_Name 01 Hansen, Ola 02 Svendson, Tove 03 Svendson, Stephen 04 Pettersen, Kari Employees_USA E_ID E_Name 01 Turner, Sally 02 Kent, Clark 03 Svendson, Stephen 04 Scott, Stephen list all the different employees in Norway and USA SELECT E_Name FROM Employees_Norway UNION SELECT E_Name FROM Employees_USA; E_Name Hansen, Ola Svendson, Tove Svendson, Stephen Pettersen, Kari Turner, Sally Kent, Clark Scott, Stephen 41

42 UNION Example 2 SELECT custno FROM customer WHERE custcity= Riyadh UNION SELECT custno FROM orders WHERE prodno=102; CUSTNO // union of the two queries custno custnam e custst custcity age 1 C1 Olaya St Jeddah 20 2 C2 Mains St Riyadh 30 3 C3 Mains Rd Riyadh 25 4 C4 Mains Rd Dammam 5 C5 Mains Rd Riyadh ordno orddate custno prodno quantity 1 01-jan jan jan jan jan mar

43 MINUS the MINUS operator returns only unique rows returned by the first query but not by the second. Takes the result set of one SELECT statement, and removes those rows that are also returned by a second SELECT statement. SQL MINUS Syntax SELECT column_name(s) FROM table_name1 MINUS SELECT column_name(s) FROM table_name2 ; 43

44 MINUS Example 1 Example: List the products that had never been ordered by customers SELECT prodno FROM product MINUS SELECT prodno FROM orders; //difference from the two queries PRODNO prodno prodname proddes price 100 P0 Food P1 healthy food P P3 self_raising flour,80%wheat P4 network 80x 300 ordno orddate custno prodno quantity 1 01-jan jan jan jan jan mar

45 INTERSECT The INTERSECT operator returns only those rows returned by both queries. Returns only those rows that are returned by each of two SELECT statements. SQL INTERSECT Syntax SELECT column_name(s) FROM table_name1 INTERSECT SELECT column_name(s) FROM table_name2 ; 45

46 INTERSECT Example: List the customers from Riyadh city who ordered product 102 SELECT custno FROM customer WHERE custcity= Riyadh' INTERSECT SELECT custno FROM orders WHERE prodno=102; CUSTNO // intersect of the two queries custn o custname custst custcity age 1 C1 Olaya St Jeddah 20 2 C2 Mains St Riyadh 30 3 C3 Mains Rd Riyadh 25 4 C4 Mains Rd Dammam 5 C5 Mains Rd Riyadh ordno orddate custno prodno quantit y 1 01-jan jan jan jan jan mar

47 Examples EMPLOYEE Employee No. First Name Last Name Dept Number Salary E1 Mandy Smith D E2 Daniel Hodges D E3 Shaskia Ramanthan D DEPENDENT Employee No. First Name Last Name Date of Birth E1 Joshua Smith 12-Jun-1998 E3 Jay Ramanthan 04-Jan-1996 E1 Jemima Smith 08-Sep

48 Examples SELECT employeeno, firstname, lastname FROM EMPLOYEE UNION SELECT employeeno, firstname, lastname FROM DEPENDENT; SELECT employeeno FROM EMPLOYEE INTERSECT SELECT employeeno FROM DEPENDENT 48

49 49

50 EMPLOYEE Table Example1 EMPLOYEE_ID LAST_NAME FIRST_NAME JOB_ID MANAGER_ID SALARY COMM DEPARTMENT_ID 7369 SMITH JOHN NULL ALLEN KEVIN DOYLE JEAN NULL DENNIS LYNN NULL BAKER LESLIE NULL WARK CYNTHIA SELECT department_id, count(*), max(salary), min(salary) FROM employee GROUP BY department_id; DEPARTMENT_ID COUNT(*) MAX(SALARY) MIN(SALARY)

51 EMPLOYEE Table Example2 EMPLOYEE_ID LAST_NAME FIRST_NAME JOB_ID MANAGER_ID SALARY COMM DEPARTMENT_ID 7369 SMITH JOHN NULL ALLEN KEVIN DOYLE JEAN NULL DENNIS LYNN NULL BAKER LESLIE NULL WARK CYNTHIA SELECT Employee_ID, FIRST_NAME,DEPARTMENT_ID FROM employee WHERE salary=(select max(salary) FROM employee); Employee_ID FIRST_NAME DEPARTMENT_ID JEAN 30 51

52 EMPLOYEE Table Example3 EMPLOYEE_ID LAST_NAME FIRST_NAME JOB_ID MANAGER_ID SALARY COMM DEPARTMENT_ID 7369 SMITH JOHN NULL ALLEN KEVIN DOYLE JEAN NULL DENNIS LYNN NULL BAKER LESLIE NULL WARK CYNTHIA SELECT Employee_ID FROM employee WHERE department_id IN (SELECT department_id FROM department WHERE a e= SALES ; DEPARTMENT Department_ID Name Location_ID 10 ACCOUNTING RESEARCH SALES OPERATIONS 167 EMPLOYEE_ID

53 EMPLOYEE Table Example4 EMPLOYEE_ID LAST_NAME FIRST_NAME JOB_ID MANAGER_ID SALARY COMM DEPARTMENT_ID 7369 SMITH JOHN NULL ALLEN KEVIN DOYLE JEAN NULL DENNIS LYNN NULL BAKER LESLIE NULL WARK CYNTHIA SELECT name FROM department d WHERE NOT EXISTS (SELECT last_name FROM employee e WHERE d.department_id=e.department_id); DEPARTMENT Department_ID Name Location_ID 10 ACCOUNTING RESEARCH SALES OPERATIONS 167 NAME ACCOUNTING 53

54 EMPLOYEE Table Example4 LAST_NAME DEPARTMENT_ID Department_ID Name SMITH RESEARCH ALLEN SALES DOYLE SALES DENNIS SALES BAKER OPERATIONS WARK SALES ACCOUNTING Department Not exist 54

55 EMPLOYEE Table Example5 EMPLOYEE_ID LAST_NAME FIRST_NAME JOB_ID MANAGER_ID SALARY COMM DEPARTMENT_ID 7369 SMITH JOHN NULL ALLEN KEVIN DOYLE JEAN NULL DENNIS LYNN NULL BAKER LESLIE NULL WARK CYNTHIA LAST_NAME DEPARTMENT_ID NAME BAKER 40 OPERATIONS 10 ACCOUNTING DEPARTMENT Department_ID Name Location_ID 10 ACCOUNTING RESEARCH SALES OPERATIONS 167 SELECT last_name, d.department_id, d.name FROM employee e, department d WHERE e.department_id (+)= d.department_id AND d.department_id in (SELECT department_id FROM depart e t WHERE a e IN ACCOUNTING, OPERATIONS ; 55

56 EMPLOYEE Table Example5 LAST_NAME LAST_NAME DEPARTMENT_ID DEPARTMENT_ID Department_ID Department_ID Name Name LAST_NAME SMITH SMITH Department_ID Name RESEARCH RESEARCH BAKER ALLEN ALLEN OPERATIONS SALES SALES DOYLE DOYLE ACCOUNTING SALES SALES DENNIS DENNIS SALES SALES BAKER BAKER OPERATIONS OPERATIONS WARK WARK SALES SALES LAST_NAME DEPARTMENT_ID NAME ACCOUNTING ACCOUNTING BAKER 40 OPERATIONS 10 ACCOUNTING SELECT last_name, d.department_id, d.name FROM employee e, department d WHERE e.department_id (+)= d.department_id AND d.department_id in (SELECT department_id FROM depart e t WHERE a e IN ACCOUNTING, OPERATIONS ; 56

57 EMPLOYEE Table Example6 EMPLOYEE_ID LAST_NAME FIRST_NAME JOB_ID MANAGER_ID SALARY COMM DEPARTMENT_ID 7369 SMITH JOHN NULL ALLEN KEVIN DOYLE JEAN NULL DENNIS LYNN NULL BAKER LESLIE NULL WARK CYNTHIA SELECT employee_id, First_name, Last_name, Salary FROM employee WHERE last_name like D% ; EMPL OYEE_ID FIRST_NAME LAST_NAME SALARY JEAN DOYLE LYNN DENNIS

58 58

59 References Data ase Systems: A Practical Approach to Design, Implementation and Management. Tho as Connolly, Carolyn Begg. 5 th Edition, Addison-Wesley,

LECTURE10: DATA MANIPULATION IN SQL, ADVANCED SQL QUERIES

LECTURE10: DATA MANIPULATION IN SQL, ADVANCED SQL QUERIES LECTURE10: DATA MANIPULATION IN SQL, ADVANCED SQL QUERIES Ref. Chapter5 From Database Systems: A Practical Approach to Design, Implementation and Management. Thomas Connolly, Carolyn Begg. 1 IS220: D a

More information

Structured Query Language (SQL) lab syllabus 4 th science. SQL is used to communicate with a database. it is the standard language for relational

Structured Query Language (SQL) lab syllabus 4 th science. SQL is used to communicate with a database. it is the standard language for relational Structured Query Language (SQL) lab syllabus 4 th science Introduction : * what is sql? SQL is used to communicate with a database. it is the standard language for relational database management systems.

More information

Lecture11: Transaction Control Language Data Control Language

Lecture11: Transaction Control Language Data Control Language IS220 : Database Fundamentals Lecture11: Transaction Control Language Data Control Language College Compu a Informati Science Informati Syste De Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Transaction

More information

Retrieving Data from Multiple Tables

Retrieving Data from Multiple Tables Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Database Lab (ECOM 4113) Lab 5 Retrieving Data from Multiple Tables Eng. Mohammed Alokshiya November 2, 2014 An JOIN clause

More information

LECTURE11: TRANSACTION CONTROL LANGUAGE DATA CONTROL LANGUAGE

LECTURE11: TRANSACTION CONTROL LANGUAGE DATA CONTROL LANGUAGE LECTURE11: TRANSACTION CONTROL LANGUAGE DATA CONTROL LANGUAGE Ref. Chapter6 From Database Systems: A Practical Approach to Design, Implementation and Management. Thomas Connolly, Carolyn Begg. 1 IS220

More information

Intermediate SQL: Aggregated Data, Joins and Set Operators

Intermediate 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 information

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 IS220 : Database Fundamentals College of Computer and Information Sciences - Information Systems Dept. Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 Ref. Chapter6 Prepared by L.

More information

KORA. RDBMS Concepts II

KORA. RDBMS Concepts II RDBMS Concepts II Outline Querying Data Source With SQL Star & Snowflake Schemas Reporting Aggregated Data Using the Group Functions What Are Group Functions? Group functions operate on sets of rows to

More information

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 Ref. Chapter6 Prepared by L. Nouf Almujally & Aisha AlArfaj& L.Fatima Alhayan Colleg Comp Informa Scien Informa Syst D 1 IS220 : Database

More information

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables INDEX Exercise No Title 1 Basic SQL Statements 2 Restricting and Sorting Data 3 Single Row Functions 4 Displaying data from multiple tables 5 Creating and Managing Tables 6 Including Constraints 7 Manipulating

More information

ÇALIŞMA TEST SORULARI

ÇALIŞMA TEST SORULARI 1. A table has the following definition: EMPLOYEES( EMPLOYEE_ID NUMBER(6) NOT NULL, LAST_NAME VARCHAR2(10) NOT NULL, MANAGER_ID VARCHAR2(6)) and contains the following rows: (1001, 'Bob Bevan', '200')

More information

Join, Sub queries and set operators

Join, Sub queries and set operators Join, Sub queries and set operators Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS Cartesian Products A Cartesian product is formed when: A join condition is omitted A join condition is invalid

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

Database Management Systems,

Database 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 information

Database Foundations. 6-9 Joining Tables Using JOIN. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-9 Joining Tables Using JOIN. Copyright 2014, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-9 Roadmap Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML Transaction Control Language (TCL)

More information

1Z0-007 ineroduction to oracle9l:sql

1Z0-007 ineroduction to oracle9l:sql ineroduction to oracle9l:sql Q&A DEMO Version Copyright (c) 2007 Chinatag LLC. All rights reserved. Important Note Please Read Carefully For demonstration purpose only, this free version Chinatag study

More information

Introduction to Oracle9i: SQL

Introduction to Oracle9i: SQL Oracle 1z0-007 Introduction to Oracle9i: SQL Version: 22.0 QUESTION NO: 1 Oracle 1z0-007 Exam Examine the data in the EMPLOYEES and DEPARTMENTS tables. You want to retrieve all employees, whether or not

More information

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-4 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

Oracle Database SQL Basics

Oracle Database SQL Basics Oracle Database SQL Basics Kerepes Tamás, Webváltó Kft. tamas.kerepes@webvalto.hu 2015. február 26. Copyright 2004, Oracle. All rights reserved. SQL a history in brief The relational database stores data

More information

Lecture3: Data Modeling Using the Entity-Relationship Model.

Lecture3: Data Modeling Using the Entity-Relationship Model. College of Computer and Information Sciences - Information Systems Dept. Lecture3: Data Modeling Using the Entity-Relationship Model. Ref. Chapter12 Prepared by L. Nouf Almujally & Aisha AlArfaj Rev. by

More information

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

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

More information

Exam: 1Z Title : Introduction to Oracle9i: SQL. Ver :

Exam: 1Z Title : Introduction to Oracle9i: SQL. Ver : Exam: 1Z0-007 Title : Introduction to Oracle9i: SQL Ver : 05.14.04 QUESTION 1 A: This query uses "+" to create outer join as it was in Oracle8i, but it requires also usage of WHERE clause in SELECT statement.b:

More information

Creating Other Schema Objects

Creating Other Schema Objects Creating Other Schema Objects Objectives After completing this lesson, you should be able to do the following: Create simple and complex views Retrieve data from views Database Objects Object Table View

More information

GIFT Department of Computing Science. CS-217/224: Database Systems. Lab-5 Manual. Displaying Data from Multiple Tables - SQL Joins

GIFT Department of Computing Science. CS-217/224: Database Systems. Lab-5 Manual. Displaying Data from Multiple Tables - SQL Joins GIFT Department of Computing Science CS-217/224: Database Systems Lab-5 Manual Displaying Data from Multiple Tables - SQL Joins V3.0 5/5/2016 Introduction to Lab-5 This lab introduces students to selecting

More information

EXISTS NOT EXISTS WITH

EXISTS NOT EXISTS WITH Subquery II. Objectives After completing this lesson, you should be able to do the following: Write a multiple-column subquery Use scalar subqueries in SQL Solve problems with correlated subqueries Update

More information

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

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, 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

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints SQL KEREM GURBEY WHAT IS SQL Database query language, which can also: Define structure of data Modify data Specify security constraints DATA DEFINITION Data-definition language (DDL) provides commands

More information

King Fahd University of Petroleum and Minerals

King Fahd University of Petroleum and Minerals 1 King Fahd University of Petroleum and Minerals Information and Computer Science Department ICS 334: Database Systems Semester 041 Major Exam 1 18% ID: Name: Section: Grades Section Max Scored A 5 B 25

More information

Lab # 6. Data Manipulation Language (DML)

Lab # 6. Data Manipulation Language (DML) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 6 Data Manipulation Language (DML) Eng. Haneen El-Masry December, 2014 2 Objective To be more familiar

More information

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database: SQL Fundamentals I. Q&As: 292

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database: SQL Fundamentals I. Q&As: 292 Vendor: Oracle Exam Code: 1Z1-051 Exam Name: Oracle Database: SQL Fundamentals I Q&As: 292 QUESTION 1 Evaluate the SQL statement: TRUNCATE TABLE DEPT; Which three are true about the SQL statement? (Choose

More information

Querying Data with Transact SQL

Querying 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 information

CHAPTER 3: QUESTIONS AND ANSWERS

CHAPTER 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 information

Oracle 1Z Oracle Database 11g SQL Fundamentals I. Download Full Version :

Oracle 1Z Oracle Database 11g SQL Fundamentals I. Download Full Version : Oracle 1Z1-051 Oracle Database 11g SQL Fundamentals I Download Full Version : https://killexams.com/pass4sure/exam-detail/1z1-051 QUESTION: 238 You need to perform these tasks: - Create and assign a MANAGER

More information

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,

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, 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 information

Exam : 1Z Title : Introduction to Oracle9i: SQL

Exam : 1Z Title : Introduction to Oracle9i: SQL Exam : 1Z0-007 Title : Introduction to Oracle9i: SQL Ver : 01-15-2009 QUESTION 1: Examine the data in the EMPLOYEES and DEPARTMENTS tables. EMPLOYEES LAST_NAME DEPARTMENT_ID SALARY Getz 10 3000 Davis 20

More information

Alkérdések II. Copyright 2004, Oracle. All rights reserved.

Alkérdések II. Copyright 2004, Oracle. All rights reserved. Alkérdések II. Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Write a multiple-column subquery Use scalar subqueries in SQL

More information

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.

Using the Set Operators. Copyright 2006, Oracle. All rights reserved. Using the Set Operators Objectives After completing this lesson, you should be able to do the following: Describe set operators Use a set operator to combine multiple queries into a single query Control

More information

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions What Are Group Functions? Group functions operate on sets of rows to give one result per group. Reporting Aggregated Data Using the Group Functions Maximum salary in table Copyright 2004, Oracle. All rights

More information

Subquery: There are basically three types of subqueries are:

Subquery: 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 information

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH 2017 Institute of Aga Network Database LECTURER NIYAZ M. SALIH Database: A Database is a collection of related data organized in a way that data can be easily accessed, managed and updated. Any piece of

More information

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

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, 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

RETRIEVING DATA USING THE SQL SELECT STATEMENT

RETRIEVING DATA USING THE SQL SELECT STATEMENT RETRIEVING DATA USING THE SQL SELECT STATEMENT Course Objectives List the capabilities of SQL SELECT statements Execute a basic SELECT statement Development Environments for SQL Lesson Agenda Basic SELECT

More information

Handout 9 CS-605 Spring 18 Page 1 of 8. Handout 9. SQL Select -- Multi Table Queries. Joins and Nested Subqueries.

Handout 9 CS-605 Spring 18 Page 1 of 8. Handout 9. SQL Select -- Multi Table Queries. Joins and Nested Subqueries. Handout 9 CS-605 Spring 18 Page 1 of 8 Handout 9 SQL Select -- Multi Table Queries. Joins and Nested Subqueries. Joins In Oracle https://docs.oracle.com/cd/b19306_01/server.102/b14200/queries006.htm Many

More information

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH Institute of Aga 2018 Microsoft SQL Server LECTURER NIYAZ M. SALIH Database: A Database is a collection of related data organized in a way that data can be easily accessed, managed and updated. Any piece

More information

Data Manipulation Language (DML)

Data Manipulation Language (DML) In the name of Allah Islamic University of Gaza Faculty of Engineering Computer Engineering Department ECOM 4113 DataBase Lab Lab # 3 Data Manipulation Language (DML) El-masry 2013 Objective To be familiar

More information

Introduction 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) 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 information

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects.

Set 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 information

SQL Queries. COSC 304 Introduction to Database Systems SQL. Example Relations. SQL and Relational Algebra. Example Relation Instances

SQL 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 information

Relational Algebra. Mr. Prasad Sawant. MACS College. Mr.Prasad Sawant MACS College Pune

Relational Algebra. Mr. Prasad Sawant. MACS College. Mr.Prasad Sawant MACS College Pune Relational Algebra Mr. Prasad Sawant MACS College Pune MACS College Relational Algebra Tuple - a collection of attributes which describe some real world entity. Attribute - a real world role played by

More information

Real-World Performance Training SQL Introduction

Real-World Performance Training SQL Introduction Real-World Performance Training SQL Introduction Real-World Performance Team Basics SQL Structured Query Language Declarative You express what you want to do, not how to do it Despite the name, provides

More information

COSC 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 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 information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Alexandra Roatiş David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2016 CS 348 SQL Winter

More information

Oracle 1Z Oracle Database 11g : SQL Fundamentals I. Download Full Version :

Oracle 1Z Oracle Database 11g : SQL Fundamentals I. Download Full Version : Oracle 1Z0-051 Oracle Database 11g : SQL Fundamentals I Download Full Version : http://killexams.com/pass4sure/exam-detail/1z0-051 Answer: D QUESTION: 183 View the Exhibits and examine the structures of

More information

Manipulating Data. Copyright 2004, Oracle. All rights reserved.

Manipulating Data. Copyright 2004, Oracle. All rights reserved. Manipulating Data Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement

More information

Database Programming - Section 7. Instructor Guide

Database Programming - Section 7. Instructor Guide Database Programming - Section 7 Instructor Guide Table of Contents...1 Lesson 1 - Multiple-Row Subqueries...1 What Will I Learn?...3 Why Learn It?...4...5 Try It / Solve It...12 Lesson 2 - Practice Exercises

More information

Lecture4: Guidelines for good relational design Mapping ERD to Relation. Ref. Chapter3

Lecture4: Guidelines for good relational design Mapping ERD to Relation. Ref. Chapter3 College of Computer and Information Sciences - Information Systems Dept. Lecture4: Guidelines for good relational design Mapping ERD to Relation. Ref. Chapter3 Prepared by L. Nouf Almujally & Aisha AlArfaj

More information

CS2 Current Technologies Lecture 3: SQL - Joins and Subqueries

CS2 Current Technologies Lecture 3: SQL - Joins and Subqueries T E H U N I V E R S I T Y O H F R G E D I N B U CS2 Current Technologies Lecture 3: SQL - Joins and Subqueries Chris Walton (cdw@dcs.ed.ac.uk) 11 February 2002 Multiple Tables 1 Redundancy requires excess

More information

RDBMS- 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. 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 information

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved. Restricting and Sorting Data Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort

More information

Fravo.com. Certification Made Easy. World No1 Cert Guides. Introduction to Oracle9i: SQL Exam 1Z Edition 1.0

Fravo.com. Certification Made Easy. World No1 Cert Guides. Introduction to Oracle9i: SQL Exam 1Z Edition 1.0 Fravo.com Certification Made Easy M C S E, C C N A, C C N P, O C P, C I W, J A V A, S u n S o l a r i s, C h e c k p o i n t World No1 Cert Guides info@fravo.com Introduction to Oracle9i: SQL Exam 1Z0-007

More information

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

ASSIGNMENT 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 information

SQL STRUCTURED QUERY LANGUAGE

SQL STRUCTURED QUERY LANGUAGE STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an

More information

Querying Data with Transact-SQL

Querying 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 information

CS2 Current Technologies Lecture 2: SQL Programming Basics

CS2 Current Technologies Lecture 2: SQL Programming Basics T E H U N I V E R S I T Y O H F R G E D I N B U CS2 Current Technologies Lecture 2: SQL Programming Basics Dr Chris Walton (cdw@dcs.ed.ac.uk) 4 February 2002 The SQL Language 1 Structured Query Language

More information

Exam Code: 1z Exam Name: Ineroduction to oracle9l:sql. Vendor: Oracle. Version: DEMO

Exam Code: 1z Exam Name: Ineroduction to oracle9l:sql. Vendor: Oracle. Version: DEMO Exam Code: 1z0-007 Exam Name: Ineroduction to oracle9l:sql Vendor: Oracle Version: DEMO Part: A 1: Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME

More information

Creating Other Schema Objects. Copyright 2004, Oracle. All rights reserved.

Creating Other Schema Objects. Copyright 2004, Oracle. All rights reserved. Creating Other Schema Objects Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Create simple and complex views Retrieve data

More information

Data Manipulation Language

Data Manipulation Language Manipulating Data Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows into a table Update rows in a table

More information

Additional Practice Solutions

Additional Practice Solutions Additional Practice Solutions Additional Practices Solutions The following exercises can be used for extra practice after you have discussed the data manipulation language (DML) and data definition language

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2017 CS 348 (Intro to DB Mgmt) SQL

More information

Database Programming with SQL

Database Programming with SQL Database Programming with SQL 2-1 Objectives This lesson covers the following objectives: Apply the concatenation operator to link columns to other columns, arithmetic expressions, or constant values to

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2016 CS 348 (Intro to DB Mgmt) SQL

More information

Database design process

Database design process Database technology Lecture 2: Relational databases and SQL Jose M. Peña jose.m.pena@liu.se Database design process 1 Relational model concepts... Attributes... EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS

More information

Lab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama

Lab # 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 information

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement GIFT Department of Computing Science [Spring 2013] CS-217: Database Systems Lab-2 Manual Data Selection and Filtering using the SELECT Statement V1.0 4/12/2016 Introduction to Lab-2 This lab reinforces

More information

Sun Certified MySQL Associate

Sun Certified MySQL Associate 310-814 Sun Certified MySQL Associate Version 3.1 QUESTION NO: 1 Adam works as a Database Administrator for a company. He creates a table named Students. He wants to create a new table named Class with

More information

Database Systems CSE 303. Outline. Lecture 06: SQL. What is Sub-query? Sub-query in WHERE clause Subquery

Database 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 information

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved. What Will I Learn? In this lesson, you will learn to: Apply SQL syntax to restrict the rows returned from a query Demonstrate application of the WHERE clause syntax Explain why it is important, from a

More information

Oracle 1Z0-007 Introduction to Oracle9i: SQL 210 Q&A

Oracle 1Z0-007 Introduction to Oracle9i: SQL 210 Q&A Oracle 1Z0-007 Introduction to Oracle9i: SQL 210 Q&A Looking for Real Exam Questions for IT Certification Exams! We guarantee you can pass any IT certification exam at your first attempt with just 10-12

More information

Three types of sub queries are supported in SQL are Scalar, Row and Table sub queries.

Three types of sub queries are supported in SQL are Scalar, Row and Table sub queries. SQL Sub-Queries What are Sub queries? SQL Sub queries are the queries which are embedded inside another query. The embedded queries are called as INNER query & container query is called as OUTER query.

More information

Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)

Querying 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 information

Using the Set Operators. Copyright 2004, Oracle. All rights reserved.

Using the Set Operators. Copyright 2004, Oracle. All rights reserved. Using the Set Operators Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Describe set operators Use a set operator to combine

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions 1Z0-051 Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions Table of Contents Introduction to 1Z0-051 Exam on Oracle Database 11g - SQL Fundamentals I 2 Oracle 1Z0-051 Certification

More information

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies Databases - 4 Other relational operations and DDL How to write RA expressions for dummies Step 1: Identify the relations required and CP them together Step 2: Add required selections to make the CP Step

More information

Database Technology. Topic 3: SQL. Olaf Hartig.

Database Technology. Topic 3: SQL. Olaf Hartig. Olaf Hartig olaf.hartig@liu.se Structured Query Language Declarative language (what data to get, not how) Considered one of the major reasons for the commercial success of relational databases Statements

More information

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel 1 In this chapter, you will learn: The basic commands

More information

Tables From Existing Tables

Tables From Existing Tables Creating Tables From Existing Tables After completing this module, you will be able to: Create a clone of an existing table. Create a new table from many tables using a SQL SELECT. Define your own table

More information

1) Introduction to SQL

1) Introduction to SQL 1) Introduction to SQL a) Database language enables users to: i) Create the database and relation structure; ii) Perform insertion, modification and deletion of data from the relationship; and iii) Perform

More information

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-3 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

CSC 261/461 Database Systems Lecture 5. Fall 2017

CSC 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 information

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

PASS4TEST. IT Certification Guaranteed, The Easy Way!  We offer free update service for one year PASS4TEST \ http://www.pass4test.com We offer free update service for one year Exam : 1z1-051 Title : Oracle Database: SQL Fundamentals I Vendor : Oracle Version : DEMO Get Latest & Valid 1Z1-051 Exam's

More information

QUETZALANDIA.COM. 5. Data Manipulation Language

QUETZALANDIA.COM. 5. Data Manipulation Language 5. Data Manipulation Language 5.1 OBJECTIVES This chapter involves SQL Data Manipulation Language Commands. At the end of this chapter, students should: Be familiar with the syntax of SQL DML commands

More information

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data.

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data. DATA 301 Introduction to Data Analytics Relational Databases Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Relational Databases? Relational

More information

Querying Data with Transact-SQL

Querying 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 information

Database Programming with SQL

Database Programming with SQL Database Programming with SQL 12-2 Objectives In this lesson, you will learn to: Construct and execute an UPDATE statement Construct and execute a DELETE statement Construct and execute a query that uses

More information

HR Database. Sample Output from TechWriter 2007 for Databases

HR Database. Sample Output from TechWriter 2007 for Databases Table of Contents...3 Tables... 4 COUNTRIES... 5 DEPARTMENTS... 6 EMPLOYEES... 7 JOBS... 9 JOB_HISTORY... 10 LOCATIONS...12 REGIONS...13 Views...14 EMP_DETAILS_VIEW... 15 Procedures...17 SECURE_DML...18

More information

Vendor: Oracle. Exam Code: 1Z Exam Name: MySQL 5.0, 5.1 and 5.5 Certified Associate Exam. Version: Demo

Vendor: Oracle. Exam Code: 1Z Exam Name: MySQL 5.0, 5.1 and 5.5 Certified Associate Exam. Version: Demo Vendor: Oracle Exam Code: 1Z0-870 Exam Name: MySQL 5.0, 5.1 and 5.5 Certified Associate Exam Version: Demo QUESTION: 1 You work as a Database Administrator for. You have created a table named Student.

More information

Group A: Assignment No 2

Group A: Assignment No 2 Group A: Assignment No 2 Regularity (2) Performance(5) Oral(3) Total (10) Dated Sign Title of Assignment: SQL Joins in MySQL using 3-tier Problem Definition: DBMS using connections ( Client-application

More information

Types. Inner join ( Equi Joins ) Outer(left, right, full) Cross. Prepared By : - Chintan Shah & Pankti Dharwa 2

Types. 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 information