Complex queries Flashcards
1
Q
- Describe the IN operator
A
- Used in
WHERE
clause to determine if a value is in several listed values
2
Q
Describe the BETWEEN operator
A
- Alternative to using ≥ and ≤
- Note that this is inclusive of the min and max values
- note that The
BETWEEN
operator can be used with any data types for which comparison operators, like < > =, are valid.
3
Q
- Does BETWEEN work on CHAR types?
A
The BETWEEN
operator can be used with any data types for which comparison operators, like < > =, are valid. CHAR
and VARCHAR
are valid
4
Q
- Describe the LIKE operator
A
- Matches text against a pattern using two ‘wildcard’ characters:
%
and_
5
Q
- What does the ‘%’ operator do?
A
-
%
matches any number of characters
6
Q
- What does the
_
operator do?
A
-
_
matches exactly 1 character
7
Q
- Describe the DISTINCT clause
A
- Used to return only unique or distinct values
8
Q
- Describe the ORDER BY clause
A
- Returns results in ascending order
9
Q
- How would one return a series of strings in descending order using the ORDER BY clause?
A
- Can add
DESC
keyword if the reverse is desired
10
Q
- Describe some SQL string functions
A
CONCAT(s1, s2, …) which returns the string that results from concatenating the string arguments
- LOWER(s) which returns the lowercase_s_
- TRIM(s) which returns the string_s_without leading and trailing spaces
11
Q
- Describe some SQL numeric functions
A
- ABS(n) which returns the absolute value of_n
- POW(x, y) which returns x to the power of y
12
Q
- Describe some SQL date functions
A
- CURDATE(), CURTIME(), NOW() which returns the current date, time, or date and time in
'YYYY-MM-DD'
,'HH:MM:SS'
, or'YYYY-MM-DD HH:MM:SS'
format- DATE(expr) TIME(expr) which Extracts the date or time from a date or datetime expression_expr_
- DAY(d) MONTH(d) YEAR(d) which Returns the day, month, or year from date_d_
13
Q
- What is an aggregate function?
A
- Processes values from a set of rows and returns a summary value
14
Q
- Describe the GROUP BY clause
A
- Consists of the GROUP BY keyword and one or more columns
- Commonly used with aggregate functions
- Each simple or composite value of the columns becomes a group
- Then the aggregate function is completed, and returns one row for each group
15
Q
- Describe the HAVING clause
A
-
HAVING
is used withGROUP BY
to filter group results
16
Q
- How do aggregate functions treat NULL values?
A
- Aggregate functions ignore null values
17
Q
- How do arithmetic functions treat NULL values?
A
- Arithmetic operations return null if any operand is null
18
Q
- Describe a
join
statement
A
- Aggregating data from multiple tables is called ‘joining’
- A
join
is aSELECT
statement that combines data from two tables
- A