WHERE Syntax Flashcards
What is the WHERE statement syntax?
Column, Operator, and Value
When do you need to add quotes around a value in a WHERE statement?
For date values like ‘12/08/1991’ and Text Values like ‘Smith’
When do you not need to add quote values for a WHERE statement?
For number values like the number 72
How would you write a WHERE statement where you compare columns against each other?
WHERE ColumnName1 operator ColumnName2
List the WHERE operators?
= (equal), <> and != (not equal) > (greater than) < (less than) >= (greater than or equal to) <= (less than or equal)
What are two ways you can use parenthesis in a WHERE clause?
To prioritize order of search
EX: WHERE Country = ‘Brazil’
OR (Country = ‘USA’ AND State = ‘CA’)
And to group together search expressions
AB.Title=T.Name AND G.Name IN (‘Rock’,’Latin’) AND AT.NAME NOT LIKE ‘[G-Z]%’)
OR
(AT.Name. = ‘Iron Maiden’ AND G.Name = ‘Blues’)
What does NULL represent?
NULL represents a missing or unknown value in the WHERE statement
Why can’t use use operators to for the NULL value?
Operators do not work with NULL values because NULL signifies an unknown value, and any comparison with an unknown value is also unknown.
Is this statement valid, and why?
SELECT * FROM Employees WHERE Department = NULL
That statement was not valid because it used an operator.
Here’s an example of a valid statement:
SELECT * FROM Employees WHERE Department IS NULL;
What keyword would you use to search for values within a range?
The BETWEEN keyword
What datatypes can you use with the BETWEEN value AND value keyword?
Date/Time, Alphanumeric, and Numeric
What WHERE keyword would you use if you needed to filter several values?
Use the IN keyword.
What’s the usage for the LIKE keyword?
The LIKE keyword in the WHERE clause is used to search for a specified pattern in a column. It is typically used with string data types to find rows where the column values match a particular pattern.
How would you write the WHERE statement to find all Gmail emails in a list?
WHERE Email LIKE ‘%gmail%’
Why do wildcard expressions use apostrophes?
Wildcard patterns are enclosed in single quotes to indicate that they are string literals to be used with the LIKE keyword. For example ‘A’