
CIS105: Computer Applications & Information Systems Lect. 14
Author:Anda Toshiki
Updated:a day ago
Words:370
Reading:2 min
Chapter 14: More SQL Statement
14.1: Statement Review
SELECT: What fields (column) you wantfieldname: If the name is used in only one table
FROM: What table or tables contain the fieldsORDER BY: SortingDISTINCT: Use afterSELECTwhen you only want to show each vale of the selected field(s) onceLIMIT: Use when you want to limit the number of records produced
14.2: New SQL Statements
WHERE: Applies conditions, filtersWHEREclause conditions follow a pattern: field + comparison operator + value- sql
WHERE crime.iucr_no = 420WHERE crime.iucr_no = 420
Comparison Operators:
>: Returns all records larger than the specified value>=: Returns all records that are at least as large as the specified value (including the value)<: Returns all records smaller than the specified value<=: Returns all records that are at least as small as the specified value (including the value)=: Returns all records that are exactly equal to the specified value<>: Returns all records that are not equal to the specified value
NULL: An empty valueNOT: Can be used to create a condition that reverses the logic of any condition- Similar logic to the
NOTfunction in Excel
- Similar logic to the
AND: Both conditions must be met for row to be included in queryOR: Used to combine criteria when we want our results to mach any criteriaBETWEEN: Shorthand way to include values in a rangeIN: Shorthand way to include values in a rangeLIKE: Use this statement when you aren't sure of the values in a record%: any combination of characters%Keyword: ends with keyword%Keyword%: looks for %keyword% anywhere in the recordKeyword%: starts with keyword
-substitutes for any single character'
t_p' would return 'tip', 'tap', or 'top''; but not 'stop''
p_st" would return 'past"', but not 'paste''h__s_n'would return 'hanson', 'hensen', or 'hansen'; but not 'harrison' (note that 'h%s_n' would return 'harrison')
14.3: Rules to Remember
- To combine
ANDandORstatements, you must follow the order of operations (AND1st,OR2nd)- If
ORmust be first, use()
- If
- All words must be in between
('_'),("_")- If your value contains a quotation, use double quotation or a
/ - All
#sis left as-is
- If your value contains a quotation, use double quotation or a
Toshiki's Note