SQL IS 240 – Database Management Lecture #15 – 2004-04-08 Prof. M. E. Kabay, PhD, CISSP Norwich University

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

The Relational Model and Normalization (3) IS 240 – Database Management Lecture # Prof. M. E. Kabay, PhD, CISSP Norwich University
The Relational Model and Normalization (1)
Foundations of Relational Implementation (2) IS 240 – Database Management Lecture #14 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Introduction to Database Processing IS 240 – Database Management Lecture #1 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Database Design (1) IS 240 – Database Management Lecture #10 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Foundations of Relational Implementation (1) IS 240 – Database Management Lecture #13 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Application Design (2) Database – IS 240 Lecture #23 – M. E. Kabay, PhD, CISSP Dept of Computer Information Systems Norwich University
Database Design (3) IS 240 – Database Management Lecture #12 – Prof. M. E. Kabay, PhD, CISSP Norwich University
The Relational Model and Normalization (2) IS 240 – Database Management Lecture # Prof. M. E. Kabay, PhD, CISSP Norwich University
DB Application Design (1) IS 240 – Database Management Lecture #16 – Prof. M. E. Kabay, PhD, CISSP Norwich University
1 Copyright © 2004 M. E. Kabay. All rights reserved. Database Design (2) IS 240 – Database Management Lecture #11 – Prof. M. E. Kabay, PhD,
Introduction to Database Development (1) IS 240 – Database Management Lecture #3 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Managing Multi-User Databases (2) IS 240 – Database Management Lecture #19 – Prof. M. E. Kabay, PhD, CISSP Norwich University
E-R Model (1) IS 240 – Database Management Lecture #5 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Managing Multi-User Databases (1) IS 240 – Database Management Lecture #18 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Introduction to the Course IS301 – Software Engineering Lecture #1 – M. E. Kabay, PhD, CISSP Assoc. Prof. Information Assurance Division of.
Working with MS-ACCESS IS 240 – Database Management Lecture #2 – Assoc. Prof. M. E. Kabay, PhD, CISSP Norwich University
1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 38.
Structured Query Language (SQL)
Database Queries and Structured Query Language (SQL) J.G. Zheng May 16 th 2008.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
0 - 0.
Introduction to SQL, OleDB interface to Access from VB.NET.
INFO ASSIST REPORT WRITING
CSE 1561 A Brief MySQL Primer Stephen Scott. CSE 1562 Introduction Once you’ve designed and implemented your database, you obviously want to add data.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Structured Query Language Part I Chapter Three CIS 218.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Download three SQL script files from wiki page.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
Chapter 3 Single-Table Queries
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Getting to Know SQL. © Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Copyright © Curt Hill Queries in SQL More options.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
1 Querying a Single Table Structured Query Language (SQL) - Part II.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
Getting to Know SQL. © Jim Hope 2004 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement UNION.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
SQL: Single Table Queries SELECT FROM WHERE ORDER D. Christozov / G.Tuparov INF 280 Database Systems: Single Table Queries 1.
SQL queries ordering and grouping. SWC – SQL query - ordering In a query producing a large result, it may be beneficial to order the result SQL.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Limiting Selected Rows. 2-2 Objectives Sort row output using the ORDER BY clause. Sort row output using the ORDER BY clause. Enter search criteria using.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
SQL Query Getting to the data ……..
Queries: Part 1 of 2 IS240 – DBMS Lecture # 6 –
GROUP BY & Subset Data Analysis
Chapter 4 Summary Query.
Access: SQL Participation Project
SQL Aggregation.
Section 4 - Sorting/Functions
Presentation transcript:

SQL IS 240 – Database Management Lecture #15 – Prof. M. E. Kabay, PhD, CISSP Norwich University

2 Copyright © 2004 M. E. Kabay. All rights reserved. Topics We have demo on screen Then you do in-class exercises Finally we review together Your challenges Learn syntax Given syntax, predict results Given need, compose syntax

3 Copyright © 2004 M. E. Kabay. All rights reserved. Todays Data for Practice

4 Copyright © 2004 M. E. Kabay. All rights reserved. Projections You need to choose columns (fields) SELECT columns FROMsource E.g., SELECTLastName, FirstName FROM Patient

5 Copyright © 2004 M. E. Kabay. All rights reserved. Projections (contd) If you dont want duplicate rows with respect to a particular column, use the DISTINCT modifier for each column affected: SELECTDISTINCT column FROMsource E.g., SELECTDISTINCT LastName, FirstName FROMPatient

6 Copyright © 2004 M. E. Kabay. All rights reserved. Selections You need to choose specific rows according to some condition SELECTcolumn-list FROMsource WHEREcondition E.g., SELECTPatient, MedicalStaff FROMPatientDoctor WHEREHospital='Waterbury'

7 Copyright © 2004 M. E. Kabay. All rights reserved. More About the WHERE Clause Boolean logic uses AND operator WHERE condition1 AND condition2 Logical OR for a single column uses the IN operator E.g., WHERE column IN ['value1','value2'…] Can exclude rows using NOT IN operator E.g., WHERE column NOT IN ['value1','value2'…]

8 Copyright © 2004 M. E. Kabay. All rights reserved. More About the WHERE Clause Ranges are inclusive and use the BETWEEN operator; e.g., WHERE column BETWEEN lower AND upper Generic lookups are possible using LIKE operator; e.g., WHERE column LIKE 'string' Placeholders (wildcards) in string include Single character represented by _ One or more characters represented by % MS-Access uses ? and *, respectively NULL placeholder represents empty value

9 Copyright © 2004 M. E. Kabay. All rights reserved. SORTING ORDER BY clause tells SQL how to sort; e.g., ORDER BY field1, field2... Must SELECT all columns used in ORDER BY Can specify sort order for each field ASCending DESCending; e.g, ORDER BY field1 ASC, field2 DESC

10 Copyright © 2004 M. E. Kabay. All rights reserved. Simple Math Functions COUNT SUM AVG MAX MIN can be used in the SELECT clause only Result in a "relation" of one row and one column with the result in that cell E.g., SELECT COUNT (MedicalStaff) FROMPatientDoctor If desired, can stipulate that unique values of the target column be used; e.g., SELECT COUNT (DISTINCT MedicalStaff) FROMPatientDoctor

11 Copyright © 2004 M. E. Kabay. All rights reserved. Grouping Rows Can apply math functions to groups that have the same value of a specific field; e.g., How many patients does each doctor have? SELECTMedicalStaff, COUNT(*) FROMPatientDoctor GROUP BYMedicalStaff Can group of rows; e.g, List the number of patients for doctors who have more than 1 patient SELECTMedicalStaff, COUNT(*) FROMPatientDoctor GROUP BYMedicalStaff HAVINGCOUNT(*)>1

12 Copyright © 2004 M. E. Kabay. All rights reserved. In-Class Exercises Write your name at the top of the first page Form groups of 2 or more people if you wish Complete all the exercises on the separate handout sheets Discuss your reasoning freely with each other and with the instructor at any time We will review the answers together at the end of the class

13 Copyright © 2004 M. E. Kabay. All rights reserved. Required Homework Reread Chapter 9 using the full SURVEY- QUESTION-READ-RECITE-REVIEW phases of SQ3R For Tuesday 13 April, Survey-Question Chapter 10 in preparation for the class lecture on DB application design For Thursday 15 April For a total of 64 points or 10% of the homework grade: Complete and hand in printed replies to Group 1 Questions 9.1 through 9.32

14 Copyright © 2004 M. E. Kabay. All rights reserved. Optional Homework By Thursday 29 April For 18 extra points, use the Northwind database and complete the SQL for exercise 9.33 For 38 extra points, complete all the problems in the FiredUp Project Questions on pp. 254 & 255

15 Copyright © 2004 M. E. Kabay. All rights reserved. DISCUSSION