Download presentation
Presentation is loading. Please wait.
Published byAustin West Modified over 8 years ago
1
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements
2
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
3
Clauses in a SELECT Statement SELECT … FROM … WHERE … … ORDER BY …
4
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
5
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
6
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
7
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
8
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.