Complex Queries Flashcards
The blank operator is used in a WHERE. Pause to determine if a value matches one of several values
IN
Like the IN operator, you can use blank in a WHERE clause to determine if a value doesn’t matches one of several values
NOT IN
The blank provides an alternative to determine if a value is between two other values.
BETWEEN operator
The BETWEEN operator is written how and is equivalent to value >= minValue AND value <=MaxValue
BETWEEN minValue AND maxValue
The BETWEEN operator can or cannot be used with string literals
Can
Which runs faster BETWEEN or other <=>= SQL statements
Neither. Same speed
The blank when used in a WHERE clause matches text against a pattern using wildcard characters blank and blank
LIKE operator
%
_
Blank matches any number of characters when used with LIKE
%
Blank matches only one character when used with LIKE
_
The LIKe operator performs case-blank patterns matching by default or case-blank pattern matching if followed by the blank keyword
Insensitive
Sensitive
BINARY
To search for wildcard characters % or _ a blank must precede them
/
Most relational databases provide other mechanisms to perform advanced pattern matching with blank
Regular expressions
The blank is used in a SELeCT statement to return any unique or distinct values
DISTINCT clause
The DISTINCT clause blank from results
Removes repeated values
Give the syntax for using a distinct clause
SELECT DISTINCT ColumnName
FROM TableName
A blank selects rows from a table with no guarantee the data will come back in a certain order.
SELECT
The blank clause orders selected rows by one or more columns in ascending order.
ORDER BY
The blank keyword with the ORDER BY clause orders rows in descending order
DESC
A blank operates on an expression in parentheses, called a blank, and returns a value.
Function
Argument
Each function operates on, and evaluates to, blank
Specific data types
If the argument is invalid, it returns blank
NULL
Blank returns the absolute value
ABS(n)
Blank returns the natural logarithm of n
LOG(n)
Blank returns x to the power of y
POW(x,y)
Blank returns a random number between 0(inclusive) and 1(exclusive)
RAND()
Blank returns n rounded to d decimal places
ROUND(n,d)
Blank returns the square root of n
SQRT(n)
Blank manipulate string values
String functions
Blank returns the combination of strings
CONCAT(s1,s2)
Blank returns lowercase s
LOWER(s)
Blank returns s with from changed to to
REPLACE(s,from,to)
Blank returns the substring from s starts at pos and has length len
SUBSTRING (s,pos,len)
Blank returns the string s without leading or trailing spaces
TRIM(s)
Blank returns the uppercase a
UPPER(s)
Blank functions operate in DATE, TIME, and DATETIME data types
Date and time
Blank returns the current date and time
CURDATE()
CURTIME()
NOW()
Blank extracts the date or time
DATE(exp)
TIME(exp)
Blank returns the day month or year
DAY(d)
MONTH(d)
YEAR(d)
Blank returns hour or minute or second
HOUR(t)
MINUTE(t)
SECOND(t)
Blank returns the difference between dates or times
DATEDIFF(expr1,expr2)
TIMEDIFF(expr1,expr2)
Some database systems, such as Microsoft SQL Server support a blank. These systems also support table-valued functions that return an entire table rather than an individual value.
Table data type
Blank processes values form a set of rows and returns a summary value.
Aggregate functions
Blank counts the number of rows in the set.
COUNT()
Blank finds the minimum value in the set
MIN()
Blank finds the maximum value in the set
MAX()
Blank sums all values in the set
SUM()
Blank computes the arithmetic mean of all the values in the set
AVG()
Aggregate functions appear in a blank clause and process all rows that satisfy the WHERE clause condition
SELECT
If a SELECt statement had no WHERE clause, the aggregate function processes blank
All rows
Aggregate functions are commonly used with the blank clause
GROUP BY clause
The GROUP BY clause consists of the GROUP BY keyword and blank
One or more columns
Each simple or composite value of the columns become a what ? The query computes the function separately and returns one row for each what?
Group
The GROUP BY clause appears between the blank clause, and if any, the blank clause.
WHERE
ORDER BY
Aside from the aggregate function, the blank may contain only columns that appear in the GROUP BY clause.
SELECT clause
The blank is used with the GROUP BY clause to filter group results
HAVING clause
The optional HAVING follows the blank and precedes the optional blank clause
GROUP BY
ORDER BY
Give the syntax for a GROUP BY clause
GROUP BY ColumnName
Give the syntax for a HAVING clause
GROUP BY ColumnName
HAVING FunctionResultExpression
Aggregate functions ignore blank
Null values
Arithmetic functions return blank when either operand is null
Null
In relational databases, reports are often generated from data in multiple tables. Multi-table reports are written with what?
Join statements
A blank is a selected statement that combines data from two tables
JOIN
The JOIN gets data from blank and blank to combine into a single result
Left table and right table
In a JOIN, the tables are combined by comparing columns from the left and right tables, usually with the blank
= operator
Usually, a join compares a blank of one table to the blank of another table.
Foreign Key
Primary Key
The columns in a join must have a comparable blank
Data type
When duplicate column names appear in a query, the names must be distinguished with a blank
Prefix
The prefix in a query where column names are the same is what
The table name followed by a period
Use of a prefix makes column names more complex, to simplify queries or result tables, a column name can be replaced with an blank
Alias
In order to create the alias, the alias follows the column name, separated by an optional blank.
AS keyword