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.
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
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.
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.
SQL 資料庫查詢語言 取材自 EIS, 3 rd edition By Dunn et al..
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.
 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.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
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.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
SQL Data Manipulation II Chapter 5 CIS 458 Sungchul Hong.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
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.
IST 318 – DB Administration Data Retrieval Using SELECT statements.
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.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Access Query Design. IT Fundamentals2 Access Query Design The Query design screen provides a mechanism for selecting specific data from datafile(s) by:
Writing Basic SQL SELECT Statements Lecture
Select Statement IT 350. Select Statement SELECT statement is what we use to choose, or select, the data that we want returned from the database to our.
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.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Restricting and Sorting Data
Chapter 5 Introduction to SQL.
Writing Basic SQL SELECT Statements
Building and Using Queries
Writing Basic SQL SELECT Statements
Restricting and Sorting Data
Chapter 4 Summary Query.
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
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

 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 with this pattern  IN (…, … [, …])  Specifying a list of values  IS NULL  Matching the NULL value (a special value stands for not applicable or not available) Some Useful Operators

 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 vendors in cities with a name starting with the letters ‘san’ The LIKE Keyword