SQL Programming. Student Workbook

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "SQL Programming. Student Workbook"

Transcription

1 SQL Programming Student Workbook

2 2 SQL Programming SQL Programming Published by itcourseware, Inc., 7245 South Havana Street, Suite 100, Englewood, CO Contributing Authors: Denise Geller, Rob Roselius, Danielle Waleri. Editor: Rob Roselius, Rick Sussenbach. Editorial Assistant: Jan Waleri Special thanks to: Many instructors whose ideas and careful review have contributed to the quality of this workbook, including Elizabeth Boss, Jennifer James, Roger Jones, Joe McGlynn, Jim McNally, and Kevin Smith, and the many students who have offered comments, suggestions, criticisms, and insights. Copyright by itcourseware, Inc. All rights reserved. No part of this book may be reproduced or utilized in any form or by any means, electronic or mechanical, including photo-copying, recording, or by an information storage retrieval system, without permission in writing from the publisher. Inquiries should be addressed to itcourseware, Inc., 7245 South Havana Street, Suite 100, Englewood, CO (303) All brand names, product names, trademarks, and registered trademarks are the property of their respective owners.

3 SQL Programming 3 Contents Chapter 1 - Course Introduction... 7 Course Objectives... 9 Course Overview Suggested References Chapter 2 - Relational Database and SQL Overview Chapter Objectives Review of Relational Database Terminology Review of Relational Database Terminology (Cont.) Introduction to SQL Connecting to a SQL Database Chapter 3 - SQL Queries: The SELECT Statement Chapter Objectives The SELECT Statement Creating Some Order Choosing Rows with the WHERE Clause NULL Values Compound Expressions Subqueries IN and BETWEEN The LIKE Operator Labs Chapter 4 - SQL Functions Chapter Objectives SQL Functions Using SQL Functions String Functions Numeric Functions Date Functions Conversion Functions Labs... 65

4 4 SQL Programming Chapter 5 - Data Manipulation Chapter Objectives The INSERT Statement The UPDATE Statement The DELETE Statement Transaction Management Concurrency Explicit Locking Data Inconsistencies Data Inconsistencies (cont'd) Loading Tables From External Sources Labs Chapter 6 - Data Definition and Control Statements Chapter Objectives Standard Data Types Defining Tables DEFAULT and NOT NULL Constraints Column Constraints Modifying Table Definitions Deleting a Table Definition Controlling Access to Your Tables Labs Chapter 7 - Views and Other Schema Objects Chapter Objectives Views Creating Views Using Views Indexes Sequences Synonyms Labs

5 SQL Programming 5 Chapter 8 - SQL Queries - Joins Chapter Objectives Selecting from Multiple Tables Joining Tables Joining More than Two Tables Self Joins Outer Joins Types of Outer Joins Labs Chapter 9 - Aggregate Functions and Advanced Techniques Chapter Objectives Correlated Subqueries The EXISTS Operator The Aggregate Functions Grouping Rows Combining SELECT Statements Labs Appendix 1 - Using Oracle SQL*Plus SQL*Plus The SQL Buffer Editing the SQL Buffer Tailoring Your SQL*Plus Environment Interacting with the Host Environment Viewing Table Characteristics Running SQL*Plus Scripts SQL*Plus Substitution Variables Interactive SQL*Plus Scripts Appendix 2 - Formatting Reports with SQL*Plus Controlling the Display of Columns Page Formatting Computations SQL*Plus Options for Formatting Saving the Output

6 6 SQL Programming Solutions - SQL Programming Index

7 Chapter 3 SQL Queries: The SELECT Statement 27 Chapter 3 - SQL Queries: The SELECT Statement

8 28 SQL Programming Notes

9 Chapter 3 SQL Queries: The SELECT Statement 29 Chapter Objectives Retrieve data from a table using the SQL SELECT statement. Sort the output of a SELECT statement. Filter the returned rows with a WHERE clause. Locate fields which have not yet been populated. Combine multiple search criteria in a WHERE clause using logical operators. Use subqueries to generate values for use in WHERE clause conditions. Use the IN and BETWEEN operators to match a column against multiple values. Use wildcards to search for a pattern in character data.

10 30 SQL Programming Notes The SELECT statement may query one or many tables. The data that is retrieved may be thought of as a virtual table (i.e., one that exists in memory only until the query completes). This virtual table is also referred to as the query s result set. The SELECT statement can be used to retrieve data from any or all columns from a table. For example, the following SELECT will display a list of everything about every store in the database: SELECT * FROM store; The query below will list each state (once) in which BizWare has stores: SELECT DISTINCT state FROM store; This query will retrieve each store s number and location. SELECT store_number, city, state FROM store; Expressions within the SELECT clause are calculated for each row in the result set. The default column heading on the display will match the expression. The heading may be overridden with a column alias. A column alias is a word used to replace the default heading. The following will retrieve the original and sale prices of products: SELECT description name, price orig_price, price *.75 sales_price FROM product; Oracle allows column aliases to contain spaces. You must use double quotes if the alias includes one or more spaces. SELECT description AS name, price AS orig_price, price *.75 AS "Sales Price" FROM product;

11 Chapter 3 SQL Queries: The SELECT Statement 31 The SELECT Statement SQL data retrievals are done using the SELECT statement. Data retrievals are also called queries. A SELECT statement may make use of several clauses, but minimally must include the following two: SELECT [DISTINCT] {item_list *} FROM table The SELECT clause specifies which data values will be retrieved, and will be followed by either an item_list or a *. * represents all the columns in table. item_list is a column, an expression, or a comma separated list of any combination of these. Each item in item_list will display to the screen under a column heading of the same name, unless an alias is specified. Use DISTINCT to eliminate duplicate rows from the displayed results. The FROM clause specifies a table, or comma separated list of tables, from which to retrieve data. You may concatenate field values and strings by using the doublepipe ( ) operator. SELECT firstname ' ' lastname AS Name FROM person;

12 32 SQL Programming Notes To display each store s number and location in descending order by state, and ascending order by city in each state, enter the following: SELECT store_number, city, state FROM store ORDER BY state DESC, city ASC; The original and sale price of an item may be displayed in descending price order with the following: SELECT description, price, price *.75 FROM product ORDER BY 3 DESC; An equivalent, and usually more readable, form of the above makes use of column aliases: SELECT description Name, price Original_Price, price *.75 sales_price FROM product ORDER BY sales_price DESC;

13 Chapter 3 SQL Queries: The SELECT Statement 33 Creating Some Order Data is not physically stored in a table in any specified order. Unless the RDBMS supports certain types of indexes, records are usually appended to the end of the table. The SELECT statement s ORDER BY clause is the only way to enforce sequencing on the result set. The ORDER BY clause may be included in the SELECT statement: SELECT {item_list *} FROM table [ORDER BY column [ASC DESC],...] column can either be the name or the numeric position of the column in the item_list. The result set is sorted by the first column name in the ORDER BY clause. If there are duplicate values in the first sort column, the sort is repeated on the second column in the list, and so on. The rows may be sorted in ascending (the default) or descending order. ASC and DESC may be applied independently to each column.

14 34 SQL Programming Notes To display all information for each store with a store number less than 4, enter the following: SELECT * FROM store WHERE state < 4; To display each store s number, location, and phone in the state of Nevada, enter the following: SELECT store_number, street, city, area_code, phone_number FROM store WHERE state = 'NV';

15 Chapter 3 SQL Queries: The SELECT Statement 35 Choosing Rows with the WHERE Clause Use the WHERE clause when only a subset of all the rows in a table is required. SELECT {item_list *} FROM table [WHERE conditions] The WHERE clause is evaluated once for each row in table. conditions will be one or more expressions that will evaluate to either true, false or neither (null). If the WHERE clause evaluates to true, then the current row is returned in the result set. Operators that may be used in the WHERE clause include: = equal to!=, ^=, <> not equal to >, < greater than, less than >=, <= greater than or equal to, less than or equal to Any character string values in conditions must be enclosed within single quotes.

16 36 SQL Programming Notes To display a sorted list of people who have middle initials, enter the following: SELECT lastname, firstname, mi, area_code, phone_number FROM person WHERE mi IS NOT NULL ORDER BY lastname, mi, firstname;

17 Chapter 3 SQL Queries: The SELECT Statement 37 NULL Values A null is the absence of a value. Null values are not equal to 0, blanks, or empty strings. Compare null values with the IS operator. SELECT * FROM person WHERE phone_number IS NULL; The IS operator will result in either true or false. To search for any non-null values, use IS NOT NULL. SELECT * FROM person WHERE phone_number IS NOT NULL; Any other operation with NULL yields a null value. SELECT * FROM person WHERE phone_number = NULL; This will never be true, even for rows with null values in the phone_number column!

18 38 SQL Programming Notes The query below will find all accounts having a minimum $1000 credit limit that have a non-zero balance: SELECT account_number "ACCT NUMBER", account_name name, credit_limit limit, balance FROM account WHERE credit_limit >= 1000 AND balance > 0; When an employee enters data into the system, a field for which there is no data may be skipped or have a 0 entered. When checking on the status of a store s inventory, the query below will display any products at each store that may be running low in inventory and haven t yet been reordered: SELECT product_id, store_number FROM inventory WHERE quantity_on_hand < 20 AND (quantity_on_order = 0 OR quantity_on_order IS NULL);

19 Chapter 3 SQL Queries: The SELECT Statement 39 Compound Expressions Use logical operators to group conditions in a WHERE clause. NOT will negate the condition following it. AND will result in true if both conditions are true for a row. OR will result in true if either condition is true for a row. The logical operators are evaluated based on precedence: NOT has the highest precedence, then AND, and then OR. If a WHERE clause contains both an AND and an OR, the AND will always be evaluated first. SELECT * FROM person WHERE lastname = 'Johnson' OR lastname = 'Johanson' AND firstname = 'Carole'; - This query will find Carole Johanson as well as anyone with the last name of Johnson. Use parentheses to override the precedence of these operators. SELECT * FROM person WHERE (lastname = 'Johnson' OR lastname = 'Johanson') AND firstname = 'Carole'; This query will find all people with a firstname of Carole and a lastname of either Johnson or Johanson.

20 40 SQL Programming Notes Report all personal orders made by the manager of store 4: SELECT invoice_number, amount_due FROM order_header WHERE customer_id = (SELECT manager_id FROM store WHERE store_number = 4); Show the name of the customer on invoice #2345: SELECT lastname, firstname FROM person WHERE id = (SELECT customer_id FROM order_header WHERE invoice_number = 2345);

21 Chapter 3 SQL Queries: The SELECT Statement 41 Subqueries A subquery is a SELECT statement that appears as part of another SQL statement. You may use any number of subqueries and can even nest a subquery in other subquery. The subquery must be enclosed in parentheses. The subquery can have any SQL feature except for a set operation or an ORDER BY clause. A single-row subquery returns exactly one record, while a multi-row subquery returns two or more records. In a WHERE clause, use a subquery to retrieve values to use in a condition. SELECT lastname, firstname, area_code, phone_number FROM person WHERE state!= (SELECT state FROM store WHERE store_number = 4); A subquery must return the correct number and type of columns and rows. SELECT lastname, firstname, area_code, phone_number FROM person WHERE id = (SELECT manager_id FROM store WHERE store_number = 7); Operators such as = and!= must be given one value to compare against.

22 42 SQL Programming Notes To display the same information for both Washington and Colorado, enter the following: SELECT store_number, street, city, area_code, phone_number FROM store WHERE state = 'WA' OR state = 'CO'; An equivalent query makes use of the IN operator: SELECT store_number, street, city, FROM store WHERE state IN ('WA', 'CO'); area_code, phone_number To list all store locations in California outside the 415 and 213 area codes: SELECT store_number, street, city, area_code, phone_number FROM store WHERE area_code NOT IN ('213', '415') AND state = 'CA'; To display a specific vendor s products that fall in the 100 to 500 dollar price range: SELECT description, price FROM product WHERE vendor_id = 'IBM' AND price BETWEEN 100 AND 500; To display a specific vendor s products that fall in the 100 to 500 dollar price range: SELECT description, price FROM product WHERE vendor_id = 'IBM' AND price BETWEEN 100 AND 500; To display all orders placed between April 1, 1999 and March 31, 2000: SELECT invoice_number, customer_id, order_date FROM order_header WHERE order_date BETWEEN '1-APR-1999' AND '31-MAR-00';

23 Chapter 3 SQL Queries: The SELECT Statement 43 IN and BETWEEN Use the IN (or NOT IN) operator to compare a column against several possible values. SELECT lastname, firstname FROM person WHERE state IN ('CA', 'CO'); IN is equivalent to ORing several conditions together. SELECT lastname, firstname FROM person WHERE state = 'CA' OR state = 'CO'; You may use a multi-row subquery to provide a list of values. SELECT lastname, firstname, area_code, phone_number FROM person WHERE state NOT IN (SELECT state FROM store); The subquery can return several values. Use the BETWEEN operator to compare a column against a range of inclusive values. SELECT lastname, firstname FROM person WHERE id BETWEEN 1000 AND 1999; The AND is part of the BETWEEN operator.

24 44 SQL Programming Notes SELECT id, firstname, lastname FROM person WHERE lastname LIKE 'M%ll_'; This query will match names such as: ID FIRSTNAME LASTNAME L. E. McAnally 8993 Madonna Mullally 9166 Angie Matilla 9412 Bruce McNally 9845 Neil Montville Or, to find names that end in 'son': SELECT id, lastname, firstname FROM person WHERE lastname LIKE '%son';

25 Chapter 3 SQL Queries: The SELECT Statement 45 The LIKE Operator The LIKE operator provides pattern matching for character data. With the LIKE operator, you can use wildcards: % Matches zero or more characters. _ Matches exactly one character and is position-dependent. SELECT vendor_id, name FROM vendor WHERE name LIKE '%Software%'; The string containing wildcards must be enclosed in quotes. Wildcards work only with the LIKE operator. If you need to include the % or _ characters in the search pattern, specify an escape character. An escape character removes the special meaning of the character following it. For example, to locate vendor company names that contain an underscore, modify the query with an escape parameter: SELECT name FROM vendor WHERE name LIKE '%\_%' ESCAPE '\';

26 46 SQL Programming Notes How a query is processed: 1. Form a product set consisting of every row of the table in the FROM clause. 2. If there is a WHERE clause, apply the condition to each row in the product set. A. If the condition is true for a row, retain the row. B. If the condition is false or null for a row, discard the row. 3. For each row retained, calculate the value of each item in the SELECT clause, producing a row in the result set. 4. If the DISTINCT operator was used, eliminate any duplicate rows in the result set. 5. If there is an ORDER BY clause, sort the result set rows as specified.

27 Chapter 3 SQL Queries: The SELECT Statement 47 Labs Write queries to: 1. Retrieve a list of all store locations and their manager s ids. 2. Find the name of the person who manages the store in Las Vegas. 3. Find the names of all employees supervised by the manager of the Las Vegas store. 4. List the states in which there are stores, listing each state only once. 5. List the states in which there are people, listing each state only once. 6. List the people who live in Glendale, California. 7. List the last name, first name, city, and state of everyone who lives in a city that starts with Las or Los or San. 8. Show which stores, if any, have no store manager.

28 48 SQL Programming Notes

29 Chapter 8 SQL Queries - Joins 131 Chapter 8 - SQL Queries - Joins

30 132 SQL Programming Notes

31 Chapter 8 SQL Queries - Joins 133 Chapter Objectives Collect data from multiple tables with a single query. Use the relational aspects of your database in queries. Relate columns within the same table. Define the term outer join. Use outer joins and recognize outer join syntax in different RDBMSs.

32 134 SQL Programming Notes When you join two tables, the result set consists of all of the rows that matched the join condition (and any other conditions). All rows that do not have a corresponding row in the other table are thrown out. This is called an inner join. The following query will return information only for employees; no other people from the person table will have a matching id in the employee table. SELECT p.id, lastname, title FROM person p, employee e WHERE p.id = e.id; In fact, we know that we will get information for all employees because of the foreign key from employee.id to person.id.

33 Chapter 8 SQL Queries - Joins 135 Selecting from Multiple Tables To retrieve data from more than one table in the same SELECT statement, the tables are joined together. Specify the tables in the FROM clause. SELECT lastname, title FROM person, employee WHERE person.id = employee.id; Use conditions in the WHERE clause to match rows from the tables. - These conditions are called join conditions. If you reference a column whose name appears in more than one table, you must precede the column name with the table name. WHERE person.id = employee.id; Using a table alias can save you some typing. SELECT p.id, lastname, title FROM person p, employee e WHERE p.id = e.id; Joins make full use of the relational aspects of a database; records from multiple tables are related through column values. You will often join a foreign key column to its corresponding primary or unique key. - But, there is no restriction on which columns can be used in a join condition.

34 136 SQL Programming Notes When using qualified notation, your queries will involve a lot more typing. You can reduce the amount of typing by using table aliases. A table alias is a shorthand notation for a table name in the FROM clause. Qualified notation is also used to select from a table in another schema: SELECT p.firstname, p.lastname, st.city, st.state FROM kris.person p, jody.store st WHERE st.manager_id = p.id; Other kinds of join types are: CROSS A join done without a WHERE clause (usually a bad idea). This joins each row of one table to each row of the other table. This is also called a Cartesian product. INNER Only rows that were matched are returned (the default). OUTER Returns all matched rows from both tables, plus unmatched rows from the first table (LEFT), or unmatched rows from the second table (RIGHT) or a combination of both (FULL). Qualified Notation: SELECT lastname, firstname, p.area_code p.phone_number "NUMBER", pay_amount, credit_limit, balance FROM person p, account a, employee e WHERE p.id = e.id AND e.id = a.customer_id AND pay_amount < credit_limit AND balance > pay_amount / 2; (This example finds all employees who take advantage of their inflated credit limit. Although qualified notation is only required to clarify certain columns, like id, this query might be easier to read if every column were qualified.)

35 Chapter 8 SQL Queries - Joins 137 Joining Tables Join conditions are often formed using parent/child relationships. Parent/child relationships are implemented using PRIMARY and FOREIGN keys. Most joins are equi-joins which require an exact match between two columns. There is no limit on the number of join conditions. There is no limit on the number of tables involved in a query. The more tables, the greater the hit on performance. When using a join, it is recommended that you precede every selected column with the corresponding table name. This is called qualified notation or dot notation. This is never necessary in queries involving only one table. When a column name appears in more than one of the queried tables, you must resolve ambiguity. All fields from one table can be selected: SELECT p.lastname, p.firstname, e.* FROM person p, employee e WHERE p.id = e.id;

36 138 SQL Programming Notes How a query is processed: 1. Form the product of the tables in the FROM clause. If there is only one table, then the product set consists of all the rows of that table. Otherwise, A. If a cross join is specified (that is, no join conditions), then for each row in the first table, include a row in the product for each row of the second table. B. If an inner join is specified, then for each row in the first table with a matching row in the second table, include a row in the product consisting of the matching rows. 2. If there is a WHERE clause, apply the condition to each row in the product set. If the condition contains a subquery, perform the subquery for each row as it is tested. A. If the condition is true for a row, retain the row. B. If the condition is false or null for a row, discard the row. 3. For each row retained, calculate the value of each item in the SELECT clause, producing a row in the result set. 4. If the DISTINCT operator was used, discard duplicate rows from the result set. 5. If there is an ORDER BY clause, sort the result set rows as specified.

37 Chapter 8 SQL Queries - Joins 139 Joining More than Two Tables You can join three or more tables with normal join syntax. SELECT oh.invoice_number, oi.product_id, p.description, oi.quantity FROM order_header oh, order_item oi, product p WHERE customer_id = 7042 AND oi.invoice_number = oh.invoice_number AND p.product_id = oi.product_id; Be sure each table in the FROM clause has a join condition in the WHERE clause. You need at least the number of tables minus 1 join conditions to avoid a cross join. - 4 tables, 3 conditions. - 5 tables, 4 conditions. - etc.

38 140 SQL Programming Notes Remember how a query is processed: the database engine first forms the product of the tables in the FROM clause, then applies the WHERE conditions to generate rows in the result set. For a self-join, simply name the same table twice in the FROM clause and the database engine will generate the cross product of the table with itself. Give the table two different aliases so that you can unambiguously reference columns in the SELECT list and the WHERE clause. SELECT ep.lastname, ep.firstname, emp.title, 'Supervisor: ' sp.firstname ' ' sp.lastname, 'Sup. Title: ' sup.title FROM person ep, employee emp, employee sup, person sp WHERE emp.supervisor_id = sup.id AND emp.id = ep.id AND sup.id = sp.id; In other words, in a self join, you treat a table as though it were two separate tables and just do an ordinary join.

39 Chapter 8 SQL Queries - Joins 141 Self Joins A self join queries a single table as though it were two separate tables. You must use table aliases to perform a self join. SELECT emp.id, emp.title, sup.id, sup.title FROM employee emp, employee sup WHERE emp.supervisor_id = sup.id;

40 142 SQL Programming Notes Syntax for Outer Joins The syntax for outer joins varies widely among database vendors. All of these perform the same query a list of all orders and the charge account on which the order was placed. If the order was not charged (that is, has no account number on it), we still see the order. Oracle: SELECT oh.invoice_number, oh.order_date, a.account_name FROM order_header oh, account a WHERE oh.account_number = a.account_number(+); Informix: SELECT oh.invoice_number, oh.order_date, a.account_name FROM order_header oh, OUTER account a WHERE oh.account_number = a.account_number; Sybase SQL Server (and Microsoft SQL Server): SELECT oh.invoice_number, oh.order_date, a.account_name FROM order_header oh, account a WHERE oh.account_number *= a.account_number; Sybase SQL Anywhere: SELECT oh.invoice_number, oh.order_date, a.account_name FROM order_header oh LEFT OUTER JOIN account a ON oh.account_number = a.account_number; The last example adheres to the SQL2 standard syntax for joins, which is more complete and flexible and better prevents ambiguities than the others.

41 Chapter 8 SQL Queries - Joins 143 Outer Joins An outer join retrieves all rows from one table, plus the matching rows from the second table. The column values for the non-matched (which would have come from the second table) will be null. Standard join syntax specifies which table, the left or right, will have all of its rows returned. SELECT oh.invoice_number, oh.order_date, a.account_name FROM order_header oh LEFT OUTER JOIN account a ON oh.account_number = a.account_number; All records from the LEFT table will be returned, the NULLs where information from the right table wasn't available.

42 144 SQL Programming Notes The SQL2 standard provides a complete and flexible syntax for joins, which, unfortunately, few vendors actually support. In the SQL2 syntax, joins are expressed in the FROM clause rather than the WHERE clause. SELECT oh.invoice_number, oh.order_date, a.account_name, a.balance FROM order_header oh INNER JOIN account a ON (a.account_number = oh.account_number); SELECT oh.invoice_number, oh.order_date, a.account_name, a.balance FROM order_header oh NATURAL JOIN account a; The following left outer join: SELECT oh.invoice_number, oh.order_date, a.account_name, a.balance FROM order_header oh LEFT OUTER JOIN account a ON (oh.account_number = a.account_number) WHERE oh.amount_paid = 0; Can be turned into this right outer join: SELECT oh.invoice_number, oh.order_date, a.account_name, a.balance FROM account a RIGHT OUTER JOIN order_header oh ON (a.account_number = oh.account_number) WHERE oh.amount_paid = 0;

43 Chapter 8 SQL Queries - Joins 145 Types of Outer Joins Left Outer Join All matching rows from the two tables, plus rows from the first table that have no matching rows in the second. Right Outer Join All matching rows from the two tables, plus rows from the second table that have no matching rows in the first. Full Outer Join All matching rows from the two tables, plus rows from each table that have no matching rows in the other.

44 146 SQL Programming Notes How a query is processed: 1. Form the product of the tables in the FROM clause. If there is only one table, then the product set consists of all the rows of that table. Otherwise, A. If a cross join is specified (that is, no join conditions), then for each row in the first table, include a row in the product for each row of the second table. B. If an inner join is specified, then for each row in the first table with a matching row in the second table, include a row in the product consisting of the matching rows. C. If an outer join is specified, start with the inner join of the two tables; then, I. For a left outer join, for each row in the first table with no match in the second, add a row to the product consisting of that row and a row of nulls for the second table. II. For a right outer join, for each row in the second table with no match in the first, add a row to the product consisting of that row and a row of nulls for the first table. III. For a full outer join, do both I and II. 2. If there is a WHERE clause, apply the condition to each row in the product set. If the condition contains a subquery, perform the subquery for each row as it is tested. A. If the condition is true for a row, retain the row. B. If the condition is false or null for a row, discard the row. 3. For each row retained, calculate the value of each item in the SELECT clause, producing a row in the result set. 4. If the DISTINCT operator was used, discard duplicate rows from the result set. 5. If there is an ORDER BY clause, sort the result set rows as specified.

45 Chapter 8 SQL Queries - Joins 147 Labs 1. Using joins, write queries to: a. List of all of the store locations and their manager s first name and last name. b. Find the name of the person who manages the store in Las Vegas. c. Find the names of all employees supervised by the manager of the Las Vegas store. d. List the names of everyone living in Glendale, California, who have accounts. Compare your solutions to your solutions from the earlier chapter on queries. 2. Using joins, write queries to: a. List the first name and last name of each employee. b. List the first name, last name, and pay type name of each employee. 3. Create a view called phonelist that will list the name and phone number of every employee. 4. Modify phonelist, if necessary, so that you can retrieve phone listings based on city. 5. Write a query to list orders. It should retrieve invoice number, name of the person who placed the order, product ids and quantities. 6. Modify the above query, if necessary, to include the product description of each item. 7. Modify the above query, if necessary, to include the total price to the customer (quantity times price minus discount) of each item; don't try subtotaling these!

46 148 SQL Programming Notes

47 Chapter 8 SQL Queries - Joins 149 Labs 8. The product table lists the stock threshold for everything we sell. If this value is 0, thenthe product is a special-order item that is not normally carried in stock. If the value of the stock threshold is greater than zero, then the product must be reordered whenever the quantity on hand drops below that value. Find all products that are low on inventory and must be reordered for store 1. (Optional) How would you write a DML statement that updates the on-order quantity for such items? 9. Write a query that lists all stores and their manager s names, including those which do not currently have managers. 10. Write a query that will list the first name and last name, along with the supervisor s id and title, of each employee. 11. (Optional) Modify the above query, if necessary, so that it lists all employees, even those with no supervisor. 12. (Optional) Modify the above query, if necessary, so that it also lists the supervisor s first name and last name.

48 150 SQL Programming Notes

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

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

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

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

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

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

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

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

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

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

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

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

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

Database Query 1: SQL Basics

Database Query 1: SQL Basics Database Query 1: SQL Basics CIS 3730 Designing and Managing Data J.G. Zheng Fall 2010 1 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic

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

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries COMP 5138 Relational Database Management Systems Week 5 : Basic COMP5138 "Relational Database Managment Systems" J. Davis 2006 5-1 Today s Agenda Overview Basic Queries Joins Queries Aggregate Functions

More information

Oracle Database 12c R2: SQL and PL/SQL Fundamentals Ed 2 NEW

Oracle Database 12c R2: SQL and PL/SQL Fundamentals Ed 2 NEW Oracle University Contact Us: 0800 891 6502 Oracle Database 12c R2: SQL and PL/SQL Fundamentals Ed 2 NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training

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

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com Essential SQL 2 Essential SQL This bonus chapter is provided with Mastering Delphi 6. It is a basic introduction to SQL to accompany Chapter 14, Client/Server Programming. RDBMS packages are generally

More information

RESTRICTING AND SORTING DATA QUESTIONS

RESTRICTING AND SORTING DATA QUESTIONS RESTRICTING AND SORTING DATA QUESTIONS http://www.tutorialspoint.com/sql_certificate/restricting_and_sorting_data_questions.htm Copyright tutorialspoint.com 1. Which of the following clause is used to

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

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

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

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

Using AND in a Query: Step 1: Open Query Design

Using AND in a Query: Step 1: Open Query Design Using AND in a Query: Step 1: Open Query Design From the Database window, choose Query on the Objects bar. The list of saved queries is displayed, as shown in this figure. Click the Design button. The

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

Microsoft Access 3: Understanding and Creating Queries

Microsoft Access 3: Understanding and Creating Queries Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex

More information

SQL Development Using Oracle

SQL Development Using Oracle SQL Development Using Oracle 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

More information

Click to create a query in Design View. and click the Query Design button in the Queries group to create a new table in Design View.

Click to create a query in Design View. and click the Query Design button in the Queries group to create a new table in Design View. Microsoft Office Access 2010 Understanding Queries Queries are questions you ask of your database. They allow you to select certain fields out of a table, or pull together data from various related tables

More information

Chapter 2. Restricting and Sorting Data

Chapter 2. Restricting and Sorting Data Chapter 2 Restricting and Sorting Data 1 Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query Sort the rows retrieved by a query Lesson Aim

More information

Advanced Subqueries. Schedule: Timing Topic 60 minutes Lecture 50 minutes Practice 110 minutes Total

Advanced Subqueries. Schedule: Timing Topic 60 minutes Lecture 50 minutes Practice 110 minutes Total 18 Advanced Subqueries Copyright Oracle Corporation, 2001. All rights reserved. Schedule: Timing Topic 60 minutes Lecture 50 minutes Practice 110 minutes Total Objectives After completing this lesson,

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

SQL. Short introduction

SQL. Short introduction SQL Short introduction 1 Overview SQL, which stands for Structured Query Language, is used to communicate with a database. Through SQL one can create, manipulate, query and delete tables and contents.

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server 20461 - Querying Microsoft SQL Server Duration: 5 Days Course Price: $2,975 Software Assurance Eligible Course Description About this course This 5-day instructor led course provides students with the

More 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

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: +381 11 2016811 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn Understanding the basic concepts of relational databases ensure refined code by developers.

More information

Page 2 of 5 3 ORDER BY hire_date DESC; Names, Numbers, and Arrangements Your ORDER BY clause does not need to explicitly name the column(s) by which y

Page 2 of 5 3 ORDER BY hire_date DESC; Names, Numbers, and Arrangements Your ORDER BY clause does not need to explicitly name the column(s) by which y Page 1 of 5 Welcome Brendan ( Account Help Sign Out ) United States Communities I am a... I want to... Secure Search Products and Services Solutions Downloads Store Support Training Partners About Oracle

More information

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to: D61830GC30 for Developers Summary Duration Vendor Audience 5 Days Oracle Database Administrators, Developers, Web Administrators Level Technology Professional Oracle 5.6 Delivery Method Instructor-led

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

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Introduction to SQL training

More information

PeopleSoft Query Training

PeopleSoft Query Training PeopleSoft Query Training Overview Guide Tanya Harris & Alfred Karam Publish Date - 3/16/2011 Chapter: Introduction Table of Contents Introduction... 4 Navigation of Queries... 4 Query Manager... 6 Query

More information

GET DATA FROM MULTIPLE TABLES QUESTIONS

GET DATA FROM MULTIPLE TABLES QUESTIONS GET DATA FROM MULTIPLE TABLES QUESTIONS http://www.tutorialspoint.com/sql_certificate/get_data_from_multiple_tables_questions.htm Copyright tutorialspoint.com 1.Which of the following is not related to

More information

Access Queries (Office 2003)

Access Queries (Office 2003) Access Queries (Office 2003) Technical Support Services Office of Information Technology, West Virginia University OIT Help Desk 293-4444 x 1 oit.wvu.edu/support/training/classmat/db/ Instructor: Kathy

More information

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX ISSN: 2393-8528 Contents lists available at www.ijicse.in International Journal of Innovative Computer Science & Engineering Volume 3 Issue 2; March-April-2016; Page No. 09-13 A Comparison of Database

More information

CHAPTER 12. SQL Joins. Exam Objectives

CHAPTER 12. SQL Joins. Exam Objectives CHAPTER 12 SQL Joins Exam Objectives In this chapter you will learn to 051.6.1 Write SELECT Statements to Access Data from More Than One Table Using Equijoins and Nonequijoins 051.6.2 Join a Table to Itself

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

Structured Query Language (SQL)

Structured Query Language (SQL) Chapter 7 Structured Query Language (SQL) SQL DML Commands SQL DDL Commands SQL SELECT Used to extract data from a database This is a table called Persons from the Northwind database The command SELECT

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

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

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

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

Creating SQL Queries in Microsoft SQL Server

Creating SQL Queries in Microsoft SQL Server Creating SQL Queries in Microsoft SQL Server You will begin by reading the Introduction from page 71 in the Pratt and Last textbook as well as the section Table Creation on pages 72 through 73. Then continue

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

Guide to Performance and Tuning: Query Performance and Sampled Selectivity

Guide to Performance and Tuning: Query Performance and Sampled Selectivity Guide to Performance and Tuning: Query Performance and Sampled Selectivity A feature of Oracle Rdb By Claude Proteau Oracle Rdb Relational Technology Group Oracle Corporation 1 Oracle Rdb Journal Sampled

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

Limiting Rows Using a Selection

Limiting Rows Using a Selection Limiting Rows Using a Selection EMP EMPNO ENAME JOB... DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20... EMP EMPNO ENAME JOB retrieve all employees in department

More information

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

SQL - QUICK GUIDE. Allows users to access data in relational database management systems. http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating

More information

SQL Tutorial Basics of the SELECT Statement

SQL Tutorial Basics of the SELECT Statement SQL Tutorial Basics of the SELECT Statement In a relational database, data is stored in tables. An example table would relate Social Security Number, Name, and Address: EmployeeAddressTable SSN FirstName

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

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 Server Database Coding Standards and Guidelines

SQL Server Database Coding Standards and Guidelines SQL Server Database Coding Standards and Guidelines http://www.sqlauthority.com Naming Tables: Stored Procs: Triggers: Indexes: Primary Keys: Foreign Keys: Defaults: Columns: General Rules: Rules: Pascal

More information

VBScript Database Tutorial Part 1

VBScript Database Tutorial Part 1 VBScript Part 1 Probably the most popular use for ASP scripting is connections to databases. It's incredibly useful and surprisingly easy to do. The first thing you need is the database, of course. A variety

More information

Using Subqueries to Solve Queries. Copyright 2006, Oracle. All rights reserved.

Using Subqueries to Solve Queries. Copyright 2006, Oracle. All rights reserved. Using Subqueries to Solve Queries Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that subqueries can solve List the types

More information

Student Workbook for Murach s SQL for SQL Server

Student Workbook for Murach s SQL for SQL Server Student Workbook for Murach s SQL for SQL Server How to use this workbook...2 Chapter 1...5 Chapter 2...9 Chapter 3...15 Chapter 4...18 Chapter 5...22 Chapter 6...25 Chapter 7...28 Chapter 8...31 Chapter

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

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course It's important for developers to understand the

More information

SELECT Company, Country FROM Customers WHERE Country <> 'USA'

SELECT Company, Country FROM Customers WHERE Country <> 'USA' Introduction to SQL SQL is a standard language for accessing databases.our SQL tutorial will teach you how to use SQL to access and manipulate data in:mysql, SQL Server, Access, Oracle, Sybase, DB2, and

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

Appendix A Practices and Solutions

Appendix A Practices and Solutions Appendix A Practices and Solutions Table of Contents Practices for Lesson I... 3 Practice I-1: Introduction... 4 Practice Solutions I-1: Introduction... 5 Practices for Lesson 1... 11 Practice 1-1: Retrieving

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training teaches you how to write subqueries,

More information

COURSE OUTLINE: Querying Microsoft SQL Server

COURSE OUTLINE: Querying Microsoft SQL Server Course Name 20461 Querying Microsoft SQL Server Course Duration 5 Days Course Structure Instructor-Led (Classroom) Course Overview This 5-day instructor led course provides students with the technical

More information

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Relational Database Languages Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Domain relational calculus QBE (used in Access) History of SQL Standards:

More information

Financial Data Access with SQL, Excel & VBA

Financial Data Access with SQL, Excel & VBA Computational Finance and Risk Management Financial Data Access with SQL, Excel & VBA Guy Yollin Instructor, Applied Mathematics University of Washington Guy Yollin (Copyright 2012) Data Access with SQL,

More information

Using Subqueries to Solve Problems

Using Subqueries to Solve Problems Blind Folio 357 8 Using Subqueries to Solve Problems CERTIFICATION OBJECTIVES 8.01 Define Subqueries 8.02 Describe the Types of Problems That the Subqueries Can Solve 8.03 List the Types of Subqueries

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

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-97 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals

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

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

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

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

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

More SQL: Complex Queries. This chapter describes more advanced features of the SQL language standard for relational databases.

More SQL: Complex Queries. This chapter describes more advanced features of the SQL language standard for relational databases. More SQL: Complex Queries This chapter describes more advanced features of the SQL language standard for relational databases. 5.1 More Complex SQL Retrieval Queries Because of the generality and expressive

More information

A basic create statement for a simple student table would look like the following.

A basic create statement for a simple student table would look like the following. Creating Tables A basic create statement for a simple student table would look like the following. create table Student (SID varchar(10), FirstName varchar(30), LastName varchar(30), EmailAddress varchar(30));

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

SAS SQL #2. Grouping Data Using GROUP BY Clause to group data by a column or columns

SAS SQL #2. Grouping Data Using GROUP BY Clause to group data by a column or columns SAS SQL #2 JC Wang Grouping Data Using GROUP BY Clause to group data by a column or columns GROUP BY input-column1 usually used with an aggregate function in the SELECT clause or in

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

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

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

Talking to Databases: SQL for Designers

Talking to Databases: SQL for Designers Biography Sean Hedenskog Talking to Databases: SQL for Designers Sean Hedenskog Agent Instructor Macromedia Certified Master Instructor Macromedia Certified Developer ColdFusion / Dreamweaver Reside in

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

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

SQL Simple Queries. Chapter 3.1 V3.0. Copyright @ Napier University Dr Gordon Russell

SQL Simple Queries. Chapter 3.1 V3.0. Copyright @ Napier University Dr Gordon Russell SQL Simple Queries Chapter 3.1 V3.0 Copyright @ Napier University Dr Gordon Russell Introduction SQL is the Structured Query Language It is used to interact with the DBMS SQL can Create Schemas in the

More information

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro, to your M: drive. To do the second part of the prelab, you will need to have available a database from that folder. Creating a new

More information

Querying Microsoft SQL Server (20461) H8N61S

Querying Microsoft SQL Server (20461) H8N61S HP Education Services course data sheet Querying Microsoft SQL Server (20461) H8N61S Course Overview In this course, you will learn the technical skills required to write basic Transact-SQL (T-SQL) queries

More information

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013 CSE 530A Database Management Systems Introduction Washington University Fall 2013 Overview Time: Mon/Wed 7:00-8:30 PM Location: Crow 206 Instructor: Michael Plezbert TA: Gene Lee Websites: http://classes.engineering.wustl.edu/cse530/

More information

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL) Copyright 2000-2001, University of Washington Using Multiple Operations Implementing Table Operations Using Structured Query Language (SQL) The implementation of table operations in relational database

More information

ORACLE SQL REVISION TOUR AND DATABASE FUNDAMENTALS

ORACLE SQL REVISION TOUR AND DATABASE FUNDAMENTALS ORACLE SQL REVISION TOUR AND DATABASE FUNDAMENTALS Q1. (a)define the term candidate key and foreign key with respect to database. (b) Define the term primary key and alternate key with respect to database.

More information

Standard Query Language. SQL: Data Manipulation Transparencies

Standard Query Language. SQL: Data Manipulation Transparencies Standard Query Language SQL: Data Manipulation Transparencies Objectives Purpose and importance of SQL. How to retrieve data from database using SELECT and: Use compound WHERE conditions. Sort query results

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

1.204 Lecture 3. SQL: Basics, Joins SQL

1.204 Lecture 3. SQL: Basics, Joins SQL 1.204 Lecture 3 SQL: Basics, Joins SQL Structured query language (SQL) used for Data definition (DDL): tables and views (virtual tables). These are the basic operations to convert a data model to a database

More information

P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur

P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur SQL is a standard language for accessing and manipulating databases. What is SQL? SQL stands for Structured Query Language SQL lets you access and manipulate databases SQL is an ANSI (American National

More information