Download presentation
Presentation is loading. Please wait.
Published byIra Cox Modified over 9 years ago
2
IFS180.81 Intro. to Data Management Chapter 6 Filtering your data
3
Filtering Date WHERE clause is used to filter each row in data set with the purpose of creating the given result set (applied to each row in table) WHERE clause follows the FROM clause in a SQL SELECT statement (figure 6-1) Personally, I like the WHERE to precede the ORDER BY clause (it makes logical sense to me)
4
Filtering Date Consider the WHERE clause a search condition WHERE clause may contain one or more Predicates (i.e. relational tests) of value expressions (combined with ‘and’ and ‘or’) Result of the search are: True False Null
5
Filtering Data Boolean Operator – AND First search condition Second search condition ANDTrueFalse TrueEvaluate to True. Row selected Evaluate to False. Row Rejected. FalseEvaluate to False. Row Rejected.
6
Filtering Data Boolean Operator – OR First search condition Second search condition ORTrueFalse TrueEvaluate to True. Row selected False Evaluate to True. Row selected Evaluate to False. Row Rejected.
7
Filtering Data The AND and OR tables imply only two value expressions. WARNING. I’ve never ran into a limit on the number of Predicates that can be tested. Evaluation of Predicates is controlled by ( ), starting with the inner most set of ( ). The most I’ve ever worked with it 26 predicates.
8
Filtering data Five basic predicates specified in SQL standard: Comparison Predicate (=, <>, >, =, <=) Between Predicate – specifies a range of values IN Predicate - specifies membership within a given list Like Predicate – pattern match and wildcards Null Predicate – expression evaluates to Null
9
Filtering Data – Comparison Equal and Not Equal are easy, right? What about unequal length columns? Pad Collating Sequence (for all Predicates): Operating System dependent ASC II = 95 printable characters. Numbers, Upper Case, Lower Case ASC II case insensitive. Numbers, Upper Case and Lower Case equal value (IBM) EBCDIC. Lower, Upper, Numbers
10
Filtering Data – Comparison Less Than or Greater Than Character Strings: Less Than Precedes (before), Greater Than Follows (After) Numeric. Less Than indicates less than, Greater indicates more than Date. Less Than indicates earlier (before), Greater indicates Later (after)
11
Filtering Data – Between Filter Range Filter Implemented with the SQL Between…And Predicate Important. Starting and Ending Value are part of the range selection In essence, the range filter is interpreted as value 1 >= value 2 and value 1 <= value 3
12
Filtering Data – IN Filter Set Membership – used to test value expressions for explicitly defined values IN Predicate (some programming languages use the CASE statement) Simply stated, the IN predicate is an OR statement, indicating one value expression must equal to be included in the result set.
13
Filtering Data – Pattern Matching Pattern Matching Search for patterns of string values or numeric values Search for entire values or partial values extremely helpful if you can’t spell (like me) Two special characters for searching are ‘%’ and ‘_’ (underscore). Wildcard search characters % sign indicates 0 or more characters ‘_’ sign indicates one and only one character
14
Filtering Data – Pattern Matching Where value expression LIKE pattern MS Access uses ‘*’ in place of ‘%’ and ‘?’ in place of the ‘_’ Table 6.1 (pg 162) depicts many good examples of wildcard searching Escape sequence ‘\’ used when the value expression includes wildcard characters in the actual data Don’t forget NOT (as not IN, not BETWEEN, not LIKE, not NULL)
15
Filtering Data – Pattern Matching Order of Precedence of Where clause evaluation: Positive, Negative sign Multiplication, Division Addition, Subtraction =, <>,,, Between, In, Like, IS Null Not And Or Control with parentheses ((((( ))))) Must Equal
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.