A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.

Slides:



Advertisements
Similar presentations
A Guide to SQL, Seventh Edition. Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables.
Advertisements

Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 11 Group Functions
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Introduction to Structured Query Language (SQL)
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Introduction to Oracle9i: SQL1 SQL Group Functions.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Structured Query Language Part I Chapter Three CIS 218.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Concepts of Database Management, 4th Edition, Pratt & Adamski
Introduction to Structured Query Language (SQL)
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Introduction to SQL J.-S. Chou Assistant Professor.
Concepts of Database Management, Fifth Edition
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
Analyzing Data For Effective Decision Making Chapter 3.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Querying a Database Access Project 2. 2 What is a Query?  In general, a query is a form of questioning, in a line of inquiry. A query may also refer.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Chapter 4 Multiple-Table Queries
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
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.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
1 2 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra.
© 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.
SQL: Single Table Queries SELECT FROM WHERE ORDER D. Christozov / G.Tuparov INF 280 Database Systems: Single Table Queries 1.
1 SQL II CIS*2450 Advanced Programming Concepts. 2 Data Types INTEGER –numbers without a decimal point –range is to SMALLINT –like.
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.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Lecture3b - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data Guide to Oracle 10g ITBIS373 Database Development.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
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.
More SQL: Complex Queries,
SQL – Entire Select.
Chapter 4 Summary Query.
Access: SQL Participation Project
Structured Query Language
Query Functions.
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

A Guide to SQL, Seventh Edition

Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL LIKE operator Use the SQL IN operator Sort data using the ORDER BY clause A Guide to SQL, Seventh Edition

Objectives Sort data using multiple keys and in ascending and descending order Use SQL aggregate functions Use subqueries Group data using the GROUP BY clause Select individual groups of data using the HAVING clause Retrieve columns with null values A Guide to SQL, Seventh Edition

Constructing Simple Queries Important feature of DBMS is ability to answer a wide variety of questions about the data A query is a question represented in a way that the DBMS can understand Use the SELECT command to query a database A Guide to SQL, Seventh Edition

Constructing Simple Queries SELECT-FROM-WHERE is the basic form of the command SELECT clause is the list of columns to include in query results FROM clause is the name of the table with the data being queried WHERE clause is optional, listing any conditions to apply to the data A Guide to SQL, Seventh Edition

Retrieving Certain Columns and Rows A command can retrieve specified columns and all rows  List the number, name and balance of all customers No WHERE clause is needed, because all customers are requested A Guide to SQL, Seventh Edition

Retrieving All Columns and Rows Use an asterisk (*) to indicate all columns in the SELECT clause Results will list all columns in the order in the description when the table was created List columns in SELECT clause to present columns in a different order A Guide to SQL, Seventh Edition

Using a WHERE Clause WHERE clause is used to retrieve rows that satisfy some condition  What is the name of customer number 148? A simple condition form: column name, comparison operator, and then either a column name or a value A Guide to SQL, Seventh Edition

Using a WHERE Clause Character values in SQL are case sensitive  “Grove” is different than “grove” Simple conditions can compare columns  WHERE BALANCE > CREDIT_LIMIT A Guide to SQL, Seventh Edition

Using Compound Conditions Compound conditions connect two or more simple conditions with AND, OR, and NOT operators  AND operator shows results that all simple conditions are true  OR operator shows results that any simple condition is true  NOT operator reverses the truth of the original condition A Guide to SQL, Seventh Edition

Using the BETWEEN Operator Not an essential feature in SQL Same results can be obtained without it Does make certain SELECT commands simpler to construct BETWEEN operator is inclusive  When using BETWEEN 2000 and 5000, values of 2000 or 5000 would be true A Guide to SQL, Seventh Edition

Using Computed Columns Computed column does not exist in the database but is computed using data in existing columns Computations can involve arithmetic operators  + for addition  - for subtraction  * for multiplication  / for division A Guide to SQL, Seventh Edition

Using the LIKE Operator Used to retrieve data where there may not be an exact match using wildcards LIKE %Central% will retrieve data with those characters  “3829 Central” or “Centralia” Underscore (_) represents any single character  “T_M” for TIM or TOM or T3M A Guide to SQL, Seventh Edition

Using the IN Operator IN operator allows for concise phrasing of certain conditions A Guide to SQL, Seventh Edition

Sorting ORDER BY clause to list data in a specific order Column on which data is to be sorted is the sort key Use ORDER BY clause followed by sort key Rows are sorted in ascending order unless another order is specified A Guide to SQL, Seventh Edition

Additional Sorting Options Possible to sort data by more than one key Major sort key and minor sort key List sort keys in order of importance in the ORDER BY clause For descending order sort, use DESC A Guide to SQL, Seventh Edition

Using Functions Aggregate functions calculate sums, averages, counts, minimum and maximum values to groups of rows A Guide to SQL, Seventh Edition

Using the COUNT Function Counts the number of rows in a table Use of an asterisk allowed to represent any column A Guide to SQL, Seventh Edition

Using the SUM Function Used to calculate totals of columns Column to be summed must be specified and must be numeric AVG, MAX, and MIN functions are similar, resulting in different statistics Null values are ignored and not used in these calculations A Guide to SQL, Seventh Edition

Using the DISTINCT Operator Used to ensure uniqueness in the data results A Guide to SQL, Seventh Edition

Nesting Queries Some queries will take two or more steps to obtain desired results A subquery is an inner query placed inside another query Outer query can use results of the subquery to find its results A Guide to SQL, Seventh Edition

Grouping Grouping creates groups of rows that share common characteristics Calculations in the SELECT command are performed for entire groups Data can be GROUPED BY a particular column, such as REP_NUM and then the statistics are calculated One line of output is produced for each group A Guide to SQL, Seventh Edition

Using a HAVING Clause The HAVING clause is used to restrict groups that will be included A Guide to SQL, Seventh Edition

Nulls Sometimes a condition involves a column that can be null A Guide to SQL, Seventh Edition

Summary Create queries that retrieve data from single tables using SELECT commands Comparison operators: =, >,=>,, or != Compound conditions using AND,OR, and NOT Use the BETWEEN operator Use the LIKE operator A Guide to SQL, Seventh Edition

Summary Use the IN operator Use and ORDER BY clause to sort data Process aggregate functions with COUNT, SUM,AVG,MAX, and MIN Use the DISTINCT operator and subqueries Use GROUP BY, HAVING and IS NULL A Guide to SQL, Seventh Edition