Database Queries and Structured Query Language (SQL) J.G. Zheng May 16 th 2008.

Slides:



Advertisements
Similar presentations
Structured Query Language (SQL)
Advertisements

Advanced SQL Topics Edward Wu.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Information Retrieval from Relational Databases
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
Structured Query Language (SQL)
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Using the Set Operators
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Year 6 mental test 10 second questions Numbers and number system Numbers and the number system, fractions, decimals, proportion & probability.
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL5.
1 Web-Enabled Decision Support Systems Access Introduction: Touring Access Prof. Name Position (123) University Name.
Yong Choi School of Business CSU, Bakersfield
Addition 1’s to 20.
Test B, 100 Subtraction Facts
Week 1.
Structured Query Language Part I Chapter Three CIS 218.
Concepts of Database Management, 4th Edition, Pratt & Adamski
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
Concepts of Database Management Sixth Edition
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
Computer Science 101 Web Access to Databases SQL – Extended Form.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 3 Single-Table Queries
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
Concepts of Database Management Seventh Edition
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) Structured Query Language Introduction to SQL Structured Query Language.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Hassan Tariq INTRODUCTION TO SQL What is SQL? –When a user wants to get some information from a database file, he can issue a query. – A query is a user–request.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Chapter 5 Introduction to SQL.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
 2012 Pearson Education, Inc. All rights reserved.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Chapter 4 Summary Query.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Access: SQL Participation Project
Structured Query Language
Section 4 - Sorting/Functions
Shelly Cashman: Microsoft Access 2016
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

Database Queries and Structured Query Language (SQL) J.G. Zheng May 16 th 2008

2 Overview SQL Language Query with SQL All examples can be used with the AmazonBook database Download it from the course website

3 Introduction/Review What is SQL Review: Database and DBMS (chapter 1) SQL is a standard language accepted by relational DBMS to perform database operations Some facts about SQL SQL 92 is the most commonly supported version English-like (not programming) Case insensitive Venders have different implementations

4 Concepts Review Relational model concepts review Relation : Table Row: Record Column: Field (Attribute)

5 Common Data Types Numeric INTEGER, SMALLINT DECIMAL(i,j), NUMBER(i,j) Character/String CHAR(n), VARCHAR(n) Date DATE, DATETIME See textbook page for data types implemented in Access

6 SELECT Statement SELECT statement retrieves data from database (query) The result is usually another table We will learn Defining selection criteria Sorting Calculation Grouping

7 SELECT Statement Syntax SELECT Column(s) or other expressions FROM Table(s) [WHERE …] [ORDER BY ColumnName]

8 Simple SELECT Statement Syntax SELECT * (or a list of columns ) FROM TableName Wild card: * Example SELECT * FROM Books SELECT BookTitle, ListPrice FROM Books

9 Use WHERE Clause Use WHERE clause to specify selection criteria Example SELECT * FROM Books WHERE ListPrice = SELECT BookTitle, ListPrice FROM Books WHERE ListPrice < 20 Comparison Operators =, >, =,

10 More Comparison Operators IN (value list) SELECT * FROM Books WHERE ListPrice IN (19.99, 29.99, 39.99) BETWEEN min AND max SELECT * FROM Books WHERE ListPrice BETWEEN 9.99 AND 19.99

11 String Pattern Match Fuzzy query using LIKE _ (underscore): single character wildcard ? in Access % (percentage): multiple character wildcard * in Access Example SELECT * FROM Books WHERE BookTitle LIKE '*information systems*'

12 Compound Conditions Use logical operators to connect multiple conditions AND: an intersection of the data sets OR: a union of the data sets Examples SELECT * FROM Books WHERE ListPrice = 9.99 SELECT * FROM Books WHERE PubDate=#10/1/2003# OR PubDate=#10/1/2004# SELECT * from Books WHERE Publisher = 'Que' AND Binding = 'Paperback'

13 Sorting Syntax ORDER BY Column(s) [ASC/DESC] Examples SELECT * FROM Books ORDER BY PubDate SELECT * FROM Books ORDER BY Publisher DESC, PubDate

14 Calculation Calculating columns Calculated columns are not designed directly into the table Using +, -, *, / with columns and numbers Example SELECT BookTitle, ListPrice, ListPrice * 0.1 AS Discount FROM Books WHERE ListPrice * 0.1 >= 15

15 Built-in Functions Using these functions to do statistics MIN MAX COUNT AVG SUM Example SELECT COUNT(*) FROM Books SELECT AVG(ListPrice) FROM Books WHERE Publisher = 'Prentice Hall'

16 Grouping GROUP BY: doing math with groups SELECT COUNT(*) FROM Books WHERE Publisher = 'Prentice Hall'; SELECT COUNT(*) FROM Books WHERE Publisher = 'The MIT Press'; … Or: SELECT Publisher, COUNT(*) FROM Books GROUP BY Publisher

17 A Complete Query SELECT ISBN, BookTitle, ListPrice, Publisher FROM Books WHERE BookTitle like '*Information Systems*' AND PubDate > #1/1/2002# AND ListPrice < 100 ORDER BY ListPrice

18 Exercise Using the AmazonBook database, use SQL or QBE to answer the following questions. 1. Which book is the most expensive? 2. How many books are under $100 of list price? 3. I am looking for a database book, no more than 50 dollars, and published after 1/1/2003; do you have any recommendations? I need the book title and its price. 4. What is the price per page for the books published by Que? List the book title, price, number of pages and price for page, and sort by the price per page, descending

19 Good Resources SQL Online Tutorial