Using Special Operators (LIKE and IN)

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

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh 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.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
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.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
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 and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Chapter 2 Querying a Database
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
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.
Structured Query Language
Introduction to SQL J.-S. Chou Assistant Professor.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Concepts of Database Management, Fifth Edition
Chapter 3 Single-Table Queries
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
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.
With Microsoft Office 2007 Introductory© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Introductory.
Concepts of Database Management Seventh Edition
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
Analyzing Data For Effective Decision Making Chapter 3.
A Guide to MySQL 5. 2 Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables Use a subquery.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
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
Concepts of Database Management Seventh Edition
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.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
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.
Structured Query Language
1 2 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra.
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
© 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.
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.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
SQL FUNDAMENTALS CDSE Days 2018.
Structured Query Language
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Using Special Operators (LIKE and IN) Wildcards in Access SQL Asterisk (*): collection of characters Question mark (?): any individual character Wildcards in MySQL Percent sign (%): any collection of characters Underscore (_): any individual character To use a wildcard, include the LIKE operator in the WHERE clause IN operator provides a concise way of phrasing certain conditions

Using Special Operators (LIKE and IN) (continued) FIGURE 3-27: SQL query with a LIKE operator FIGURE 3-28: Query results

Using Special Operators (LIKE and IN) (continued) FIGURE 3-28: SQL query with an IN operator FIGURE 3-29: Query results

Sorting Sort data using the ORDER BY clause Sort key: field on which to sort data When sorting data on two fields: Major sort key (or primary sort key): more important sort key Minor sort key (or secondary sort key): less important sort key

Sorting (continued) FIGURE 3-33: SQL query to sort data on multiple fields FIGURE 3-34: Query results

Built-in Functions Built-in functions (aggregate functions) in SQL COUNT: calculates number of entries SUM or AVG: calculates sum or average of all entries in a given column MAX or MIN: calculates largest or smallest values respectively

Built-in Functions (continued) FIGURE 3-35: SQL query to count records FIGURE 3-36: Query results

Subqueries Subquery: inner query Subquery is evaluated first Outer query is evaluated after the subquery

Subqueries (continued) FIGURE 3-41: SQL query with a subquery FIGURE 3-42: Query results

Grouping Create groups of records that share a common characteristic GROUP BY clause indicates grouping in SQL HAVING clause is to groups what the WHERE clause is to rows

Grouping (continued) FIGURE 3-45: SQL query to restrict the groups that are included FIGURE 3-46: Query results

Joining Tables Queries can locate data from more than one table Enter appropriate conditions in the WHERE clause To join tables, construct the SQL command as: SELECT clause: list all fields you want to display FROM clause: list all tables involved in the query WHERE clause: give the condition that will restrict the data to be retrieved to only those rows from the two tables that match

Joining Tables (continued) FIGURE 3-49: SQL query to join tables

Joining Tables (continued) FIGURE 3-50: Query results

Union Union of two tables is a table containing all rows in the first table, the second table, or both tables Two tables involved must be union compatible Same number of fields Corresponding fields must have same data types

FIGURE 3-55: SQL query to perform a union FIGURE 3-56: Query results Union (continued) FIGURE 3-55: SQL query to perform a union FIGURE 3-56: Query results

Updating Tables UPDATE command makes changes to existing data INSERT command adds new data to a table DELETE command deletes data from the database

Updating Tables (continued) FIGURE 3-57: SQL query to update data FIGURE 3-58: SQL query to insert a row

Updating Tables (continued) FIGURE 3-59: SQL query to delete rows 19

Creating a Table from a Query INTO clause Saves the results of a query as a table Specified before FROM and WHERE clauses MySQL Create the new table using a CREATE TABLE command Use an INSERT command to insert the appropriate data into the new table

Creating a Table from a Query (continued) FIGURE 3-60a: Query to create a new table (Access) 21

Creating a Table from a Query (continued) FIGURE 3-60b: Query to create a new table (for Oracle and MySQL) 22

Summary of SQL Commands Generic versions of SQL commands for every example presented in this chapter In most cases, commands in Access are identical to the generic versions For those commands that differ, both the generic version and the Access version are included

Summary Structured Query Language (SQL) is a language that is used to manipulate relational databases Basic form of an SQL query: SELECT-FROM-WHERE Use CREATE TABLE command to describe table layout to the DBMS, which creates the table In SQL retrieval commands, fields are listed after SELECT, tables are listed after FROM, and conditions are listed after WHERE In conditions, character values must be enclosed in single quotation marks

Summary (continued) Compound conditions are formed by combining simple conditions using either or both of the following operators: AND and OR Sorting is accomplished using ORDER BY clause When the data is sorted in more than one field, can have a major and minor sort key Grouping: use the GROUP BY clause HAVING clause: restricts the rows to be displayed

Summary (continued) Joining tables: use a condition that relates matching rows in the tables to be joined Built-in (aggregate) functions: COUNT, SUM, AVG, MAX, and MIN One SQL query can be placed inside another; the subquery is evaluated first UNION operator: unifies the results of two queries

Summary (continued) Calculated fields: include the calculation, the word AS, the name of the calculated field INSERT command adds a new row to a table UPDATE command changes existing data DELETE command deletes records INTO clause is used in a SELECT command to create a table containing the results of the query