IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.

Slides:



Advertisements
Similar presentations
WHERE Clause Chapter 2. Objectives Limit rows by using a WHERE clause Use the LIKE operator Effect of NULL values Use compound conditions Use the BETWEEN.
Advertisements

Chapter 4 Joining Multiple Tables
Overview of basic Queries Single Item And Query Or Query.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Restricting and Sorting Data. Consider the table employee(employee_id,last_name,job_id, department_id ) assume that you want to display all the employees.
1 SQL-Structured Query Language SQL is the most common language used for creating and querying relational databases. Many users can access a database applications.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Structured Query Language Part I Chapter Three CIS 218.
SQL Tutorials To understand some of the topics please analyze the following tutorials: The following tutorials will help:
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
IFS Intro. to Data Management Chapter 6 Filtering your data.
1 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and Custom Forms.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Microsoft Access 2010 Building and Using Queries.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Examining data using Microsoft Access Queries Using Criteria and Calculations SESSION 3.2 This section covers specifying an exact match condition in a.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
SQL - DML. Data Manipulation Language(DML) Are used for managing data: –SELECT retrieve data from the a database –INSERT insert data into a table –UPDATE.
SQL queries basics. RHS – SOC 2 SQL query An SQL query is an SQL statement, which specifies a subset of the data in the database A subset in terms of.
Lab_03: Basic SQL.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Structured Query Language
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Restrictions Objectives of the Lecture : To consider the algebraic Restrict operator; To consider the Restrict operator and its comparators in SQL.
Fall Lab 131 CS105 Lab 13 – Logical Operator Precedence and Joining Tables Announcements: MP 3 released Friday, 11/20 Honors project due: Tuesday,
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
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.
Lecture 11 SQL. Agenda SQL Select statement WHERE clause BindingSource filtering.
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
1 Section 3 - Select Statement u The Select statement allows you to... –Display Data –Specify Selection Criteria –Sort Data –Group Data for reporting –Use.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Restricting and Sorting Data
SQL Query Getting to the data ……..
Chapter 5 Introduction to SQL.
Writing Basic SQL SELECT Statements
Larry Reaves October 9, 2013 Day 16: Access Chapter 2 Larry Reaves October 9, 2013.
Building and Using Queries
Writing Basic SQL SELECT Statements
Restricting and Sorting Data
Chapter 4 Summary Query.
Writing Basic SQL SELECT Statements
Introduction To Structured Query Language (SQL)
Lesson 3 Chapter 10.
Restricting and Sorting Data
Shelly Cashman: Microsoft Access 2016
Restricting and Sorting Data
Lab 2: Retrieving Data from the Database
Presentation transcript:

IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements

 We have learned in Lab 1  The SELECT statement can have up to six clauses  The first two clauses SELECT and FROM are always used  The ORDER BY clause, when used, will be the last one  In this lab, we will practice the WHERE clause, which  Comes right after the FROM clause, and  Specifies criteria: only rows meet the conditions will be retrieved Basic SELECT Syntax

Clauses in a SELECT Statement SELECT … FROM … WHERE … … ORDER BY …

 Many conditions can be specified using comparison operators (see list on right)  These operators work with all 3 types of data commonly in use:  Numbers  Dates (e.g., >= means on or after a date)  Text string (based on alphabetical order) Using Comparison Operators Comparison Operators These operators take 2 operands (or expressions) in the form Expr1 Operator Expr2 For instance, VenderState = ‘IA’ InvoiceTotal <> 0

 We will use the Invoices table, and retrieve data from the invoice number, date, and total amount columns  Q1: Retrieve invoices with a total amount greater than $1,000  Q2: Retrieve invoices with a date before Sept 1, 2009 Queries about Invoices

 Sometimes a query needs to use a compound condition with multiple comparisons linked with logical operators:  AND  OR  NOT  Q3: Retrieve invoices with a total amount greater than $1,000 but less than $2,500  Q4: Retrieve invoices with a total amount less than $1,000 or greater than $2,500 Using Logical Operators

 BETWEEN … AND …  Specifying an inclusive range with continuous values  Q5: Rewrite Q3 using this pattern (and notice the diff.)  IN (…, … [, …])  Specifying a list of discrete values  It can be to used to simplify compound conditions using OR (e.g., state = ‘CA’ or state = ‘DC’ or state = ‘IA’)  Q6: Rewrite the compound condition above using the IN syntax Some Useful Operators

 NULL is defined as a special value that stands for not available or not applicable  For instance, an invoice that has not been paid will have a NULL value stored in the PaymentDate field  The IS NULL phrase (and IS NOT NULL )  Null is not a specific value so you cannot use compare it using any of the comparison operators  Q7: Find out invoice number, vendor ID, and invoice total of all invoices that have not been paid. Dealing with NULL Value

 LIKE is used for matching strings  A pattern is specified instead of exact values  The following wildcard characters are often used:  %matches any string of zero or more characters  _ matches any one single character  Q8: list name, city, and state of all vendors that are located in cities with a name starting with the letters 'san' The LIKE Keyword