Complex Queries Flashcards

1
Q

The blank operator is used in a WHERE. Pause to determine if a value matches one of several values

A

IN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Like the IN operator, you can use blank in a WHERE clause to determine if a value doesn’t matches one of several values

A

NOT IN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The blank provides an alternative to determine if a value is between two other values.

A

BETWEEN operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The BETWEEN operator is written how and is equivalent to value >= minValue AND value <=MaxValue

A

BETWEEN minValue AND maxValue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The BETWEEN operator can or cannot be used with string literals

A

Can

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which runs faster BETWEEN or other <=>= SQL statements

A

Neither. Same speed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The blank when used in a WHERE clause matches text against a pattern using wildcard characters blank and blank

A

LIKE operator
%
_

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Blank matches any number of characters when used with LIKE

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Blank matches only one character when used with LIKE

A

_

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The LIKe operator performs case-blank patterns matching by default or case-blank pattern matching if followed by the blank keyword

A

Insensitive
Sensitive
BINARY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

To search for wildcard characters % or _ a blank must precede them

A

/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Most relational databases provide other mechanisms to perform advanced pattern matching with blank

A

Regular expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The blank is used in a SELeCT statement to return any unique or distinct values

A

DISTINCT clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The DISTINCT clause blank from results

A

Removes repeated values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give the syntax for using a distinct clause

A

SELECT DISTINCT ColumnName
FROM TableName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A blank selects rows from a table with no guarantee the data will come back in a certain order.

A

SELECT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The blank clause orders selected rows by one or more columns in ascending order.

A

ORDER BY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The blank keyword with the ORDER BY clause orders rows in descending order

A

DESC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

A blank operates on an expression in parentheses, called a blank, and returns a value.

A

Function
Argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Each function operates on, and evaluates to, blank

A

Specific data types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

If the argument is invalid, it returns blank

A

NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Blank returns the absolute value

A

ABS(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Blank returns the natural logarithm of n

A

LOG(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Blank returns x to the power of y

A

POW(x,y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Blank returns a random number between 0(inclusive) and 1(exclusive)

A

RAND()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Blank returns n rounded to d decimal places

A

ROUND(n,d)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Blank returns the square root of n

A

SQRT(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Blank manipulate string values

A

String functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Blank returns the combination of strings

A

CONCAT(s1,s2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Blank returns lowercase s

A

LOWER(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Blank returns s with from changed to to

A

REPLACE(s,from,to)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Blank returns the substring from s starts at pos and has length len

A

SUBSTRING (s,pos,len)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Blank returns the string s without leading or trailing spaces

A

TRIM(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Blank returns the uppercase a

A

UPPER(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Blank functions operate in DATE, TIME, and DATETIME data types

A

Date and time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Blank returns the current date and time

A

CURDATE()
CURTIME()
NOW()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Blank extracts the date or time

A

DATE(exp)
TIME(exp)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Blank returns the day month or year

A

DAY(d)
MONTH(d)
YEAR(d)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Blank returns hour or minute or second

A

HOUR(t)
MINUTE(t)
SECOND(t)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Blank returns the difference between dates or times

A

DATEDIFF(expr1,expr2)
TIMEDIFF(expr1,expr2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

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.

A

Table data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Blank processes values form a set of rows and returns a summary value.

A

Aggregate functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Blank counts the number of rows in the set.

A

COUNT()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Blank finds the minimum value in the set

A

MIN()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Blank finds the maximum value in the set

A

MAX()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Blank sums all values in the set

A

SUM()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

Blank computes the arithmetic mean of all the values in the set

A

AVG()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Aggregate functions appear in a blank clause and process all rows that satisfy the WHERE clause condition

A

SELECT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

If a SELECt statement had no WHERE clause, the aggregate function processes blank

A

All rows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Aggregate functions are commonly used with the blank clause

A

GROUP BY clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

The GROUP BY clause consists of the GROUP BY keyword and blank

A

One or more columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

Each simple or composite value of the columns become a what ? The query computes the function separately and returns one row for each what?

A

Group

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

The GROUP BY clause appears between the blank clause, and if any, the blank clause.

A

WHERE
ORDER BY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

Aside from the aggregate function, the blank may contain only columns that appear in the GROUP BY clause.

A

SELECT clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

The blank is used with the GROUP BY clause to filter group results

A

HAVING clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

The optional HAVING follows the blank and precedes the optional blank clause

A

GROUP BY
ORDER BY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

Give the syntax for a GROUP BY clause

A

GROUP BY ColumnName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Give the syntax for a HAVING clause

A

GROUP BY ColumnName
HAVING FunctionResultExpression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Aggregate functions ignore blank

A

Null values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

Arithmetic functions return blank when either operand is null

A

Null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

In relational databases, reports are often generated from data in multiple tables. Multi-table reports are written with what?

A

Join statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

A blank is a selected statement that combines data from two tables

A

JOIN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

The JOIN gets data from blank and blank to combine into a single result

A

Left table and right table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

In a JOIN, the tables are combined by comparing columns from the left and right tables, usually with the blank

A

= operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

Usually, a join compares a blank of one table to the blank of another table.

A

Foreign Key
Primary Key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

The columns in a join must have a comparable blank

A

Data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

When duplicate column names appear in a query, the names must be distinguished with a blank

A

Prefix

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

The prefix in a query where column names are the same is what

A

The table name followed by a period

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

Use of a prefix makes column names more complex, to simplify queries or result tables, a column name can be replaced with an blank

A

Alias

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

In order to create the alias, the alias follows the column name, separated by an optional blank.

A

AS keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

Give the syntax for using the AS keyword

A

SELECT ColumnName AS Alias…

72
Q

A blank determines how a join query handles unmatched rows

A

JOIN clause

73
Q

A blank selects only matching left and right table rows

A

INNER JOIN

74
Q

A blank selects all left and right table rows regardless of match

A

FULL JOIN

75
Q

In a blank result table, unmatched left table rows appear with NULL values in the right table columns and vice versa

A

Full join

76
Q

The join clause appears between a blank and a blank

A

FROM clause
ON clause

77
Q

In a join query, the blank specifies the left table, and the blank specifies the right table

A

FROM
INNER JOIN or FULL JOIN

78
Q

The blank specifies the join columns

A

ON clause

79
Q

Give the syntax for a join query

A

SELECT ColumnName1, ColumnName2
FROM TableName
INNER JOIN or FULL JOIN TableName2
ON Expression;

80
Q

In some cases, the database user wants to see unmatched rows from the left or right table, but not both. To do this, relational databases support blank and blank

A

LEFT and RIGHT JOINS

81
Q

A blank selects all the left table rows, but only the matching right table rows

A

LEFT JOIN

82
Q

A blank selects all the right table rows, but only the matching left table rows

A

RIGHT JOIN

83
Q

MySQL supports INNER, LEFT, and RIGHT JOINS but not blank

A

FULL JOINS

84
Q

Give the syntax for a left or right John

A

SELECT ColumnName1, ColumnName2
FROM TableName1
LEFT JOIN or RIGHT JOIN TableName2
ON Expression;

85
Q

INNER and OUTER JOIN queries can be written without a JOIN clause. However a blank clarifies join behavior and simplifies queries.

A

JOIN clause

86
Q

Blank keyword combines the results into one table

A

UNION keyword

87
Q

Blank compares columns of two tables with the = operator.

A

Equijoin

88
Q

A blank compares columns with an operator other than =, like < and >

A

Non-equijoin

89
Q

Blank joins a table to itself

A

Self-join

90
Q

A self-join can compare any columns of a table, as long as the columns have comparable blank

A

Data types

91
Q

If a blank and a blank are in the same table, a self-join commonly compares these key columns

A

Foreign key and the referenced primary key

92
Q

In a self-join, lank are necessary to distinguish left and right tables

A

Aliases

93
Q

Blank combines the tables without comparing columns

A

CROSS JOIN

94
Q

A cross join used a CROSS JOIN clause without an blank.

A

ON clause

95
Q

In a CROSS JOIN, all possible blank from both tables appear in the result

A

Rows

96
Q

Give the syntax for a cross join

A

SELECT ColumnName1 + ColumnName2
FROM TableName
CROSS JOIN TableName2;

97
Q

A blank, sometimes called a nested query or inner query, is a query within another query.

A

Subquery

98
Q

The subquery is typically used in a blank’s WHERE clause to return data to the outer query and restrict selected results

A

SELECT statement

99
Q

The subquery is placed within blank

A

Parentheses ()

100
Q

A subquery is blank when the subquery’s WHERE clause references a column from the outer query.

A

Correlated

101
Q

In a correlated subquery, the blank selected depends on what row is currently being examined by the outer row

A

Rows

102
Q

If the column name in the correlated query is identical to a column name in the outer query, the blank differentiates the columns

A

TableName.ColumnName

103
Q

A blank can also be used in a correlated subquery to differentiate the column or table using the AS keyword

A

Alias

104
Q

Correlated sub queries commonly use the blank operator, which returns a TRUEif a subquery selects at least one row and FALSE if no rows are selected

A

EXISTS

105
Q

The blank operator returns TRUE if a subquery selects no rows and FALSE if at least one row is selected

A

NOT EXISTS

106
Q

Give the syntax for using EXISTS or NOT EXiSTS

A

SELECT ColumnName1, ColumnName2
FROM TableName
WHERE EXISTS or NOT EXiSTS
(Subquery);

107
Q

Many sub queries can be written as a blank

A

JOIN

108
Q

Most databases optimize a subquery and outer query separately, whereas blanks are optimized in one pass

A

JOINS

109
Q

Replacing a subquery with an equivalent JOIN is called blank

A

Flattening a query

110
Q

Most sub queries that follow blank or blank, or return a blank can be flattened

A

IN
EXISTS
A single value

111
Q

Most sub queries that follow blank or contain a blank clause cannot be flattened

A

NOT EXISTS
GROUP BY

112
Q

Name the five steps for flattening a query

A

1) Retain the outer query SELECT, FROM, GROUP BY, HAVING, and ORDER BY clauses
2) Add INNER JOIN clauses for each subquery table
3) move conparisons between sub query and outer query columns to ON clauses
4) Add a WHERE clause with the remaining expressions in the subquery and outer query WHERE clauses
5) if necessary, remove duplicates with SELECT DISTINCT

113
Q

To create a complex query, name the strategy a user can use (5 steps)

A

1) Examine a table diagram or other database summary to understand tables and relationships
2) Identify the tables containing the necessary data to answer the question.
3) Determine which columns should appear in the result table.
4) Write a query that joins the tables using the table’s primary and foreign keys.
5) Break the problem into simple queries, writing one part of the query at a time.

114
Q

Blank restructure table columns and data types without changes to the underlying database design.

A

Views

115
Q

A blank is a table name associated with a SELECT statement, called the view query.

A

View table

116
Q

The blank statement creates a view table and specifies the view name, query, and, optionally, column names.

A

CREATE VIEW

117
Q

In a CREATE VIEW query, If column names are not specified, column names are the same as in the blank.

A

view query result table.

118
Q

Name the syntax for a CREATE VIEW query

A

CREATE VIEW ViewName [ ( Column1, Column2, … ) ]
AS SelectStatement;

119
Q

A table specified in the view query’s FROM clause is called a blank

A

Base table

120
Q

Unlike base table data, view table data is blank

A

not normally stored

121
Q

When a view table appears in an SQL statement, the view query is blank.

A

merged with the SQL query

122
Q

In some databases, view data can be stored. A blank is a view for which data is stored at all times.

A

materialized view

123
Q

Whenever a base table changes, the corresponding view tables can also change, so materialized views must be blank

A

Refreshed

124
Q

A view can be defined on other view tables when the view query FROM clause includes additional view tables. In this case, the additional view tables are not base tables. Base tables are always blank, created as tables rather than as views.

A

source tables

125
Q

View tables have several advantages. Name three.

A

1) protect sensitive data
2) save complex queries
3) save optimized queries

126
Q

Authorizing users and programmers access to the view but not the underlying table protects the blank

A

Sensitive data

127
Q

Complex SELECT statements can be saved as a view. Database users can blank without writing the SELECT statement.

A

Reference the view

128
Q

Often, the same result table can be generated with equivalent SELECT statements. Although the results of equivalent statements are the same, performance may vary. To ensure fast execution, the blank can be saved as a view and distributed to database users.

A

Optimal query

129
Q

View tables are commonly used in SELECT statements. Using views in INSERT, UPDATE, and DELETE statements is blank

A

Problematic

130
Q

If a base table blank does not appear in a view, an insert to the view generates a NULL blank. Since blank may not be NULL, the insert is not allowed.

A

Primary key

131
Q

A view query may contain aggregate functions such as AVG() or SUM(). One aggregate value corresponds to blank. An update or insert to the view may create a new aggregate value, which must be converted to blank. The conversion is undefined, so the insert or update is not allowed.

A

Many base table values

132
Q

In a join view, foreign keys of one base table may match primary keys of another. A delete from a view might delete foreign key rows only, or primary key rows only, or both the primary and foreign key rows. The effect of the join view delete is blank and therefore not allowed.

A

Undefined

133
Q

Relational databases either disallow or severely limit view table inserts, updates, and deletes. Regardless of specific database limitations, inserts, updates, and deletes to views should be avoided. Views are best for blank.

A

Reading data

134
Q

A view insert or update may create a row that does not satisfy the view query WHERE clause. In this case, the inserted or updated row blank

A

Does not appear in the view table

135
Q

To prevent inserts or updates that appear to fail, databases that support view updates have an optional blank clause.

A

WITH CHECK OPTION

136
Q

When WITH CHECK OPTION is specified, the database blanks inserts and updates that do not satisfy the view query WHERE clause. Instead, the database generates an error message that explains the violation.

A

Rejects

137
Q

Give the syntax for a WITH CHECK OPTION

A

CREATE VIEW ViewName [ ( Column1, Column2, … ) ]
AS SelectStatement
[ WITH CHECK OPTION ];

138
Q

In his original paper on the relational model, E. F. Codd introduced formal operations for manipulating tables. Codd’s operations, called blank, have since been refined and are the theoretical foundation of SQL.

A

Relational algebra

139
Q

Relational algebra has nine operations. Each operation is denoted with a blank, often a letter of the Greek alphabet.

A

Special symbol

140
Q

Select corresponds to Latin letter s, for Select what is the symbol

A

sigma

141
Q

Project corresponds to Latin letter P, for Project. Name the symbol

A

Pi

142
Q

Product’s special symbol

A

X

143
Q

Join’s special symbol

A

multiplication symbol with vertical bars

144
Q

Union set theory’s special symbol

A

U

145
Q

Intersect set theory’s special symbol

A

Upside down U

146
Q

Difference set theory symbol

A

147
Q

Rename special symbol corresponds to Latin letter r, for Rename

A

rho

148
Q

Aggregate special symbol corresponds to Latin letter g, for group

A

Gamma

149
Q

Relational algebra is not standardized. Some authors include additional operations, such as blank and blank. Variations of the join operation, such as blank, are sometimes considered distinct operations.

A

Assign and divide
inner join, full join, and equijoin

150
Q

The select operation selects table rows based on a logical expression. The select operation is written as blank

A

Sigma symbol expression (table)

151
Q

The project operation selects table columns. The project operation is written as blank

A

Pi symbol(column1,column2)(table)

152
Q

The product operation combines two tables into one result. The result includes all columns and all combinations of rows from both tables. The product operation is written as blank

A

Table1 X Table2

153
Q

The join operation, denoted with a “bowtie” symbol, is written as

A

Table1 |X| expression Table2

154
Q

Because of theta notation, the join operation is sometimes called a blank

A

Theta join

155
Q

Blank have the same number of columns with the same data types. Column names may be different.

A

Compatible tables

156
Q

Union, intersect, and difference operate on compatible tables and, collectively, are called blank

A

set operations

157
Q

The blank combines all rows of two compatible tables into a single table. Duplicate rows are excluded from the result table.

A

Union operation

158
Q

The union operation is written as blank

A

Table1 U Table2

159
Q

Blank operates on two compatible tables and returns only rows that appear in both tables.

A

Intersect

160
Q

The intersect operation is written as

A

Table1 upsidedownU Table2

161
Q

The blank operation removes from a table all rows that appear in a second compatible table.

A

Difference

162
Q

The difference operation is written as

A

Table1 — Table2

163
Q

The UNION, INTERSECT, and MINUS keywords are part of the SQL standard. MySQL supports UNION but not INTERSECT and MINUS. In MySQL, the intersect and difference operations can be implemented as blank

A

Joins

164
Q

The blank specifies new table and column names.

A

Rename operation

165
Q

The rename operation is written as

A

rhosymbol TableName(ColumnName1, ColumnName2) (Table)

166
Q

In the rename operation, If TableName is omitted, only the blank are changed. If (ColumnName1, ColumnName2, … ) is omitted, only the blank is changed.

A

Column names
Table name

167
Q

The blank applies aggregate functions like SUM(), AVG(), MIN(), and MAX().

A

Aggregate operation

168
Q

The aggregate operation is written as

A

GroupColumn gammasymbol Function(Column) (Table)

169
Q

In the aggregate operation, If GroupColumn is omitted, the operation is equivalent to SELECT Function(Column) FROM Table and computes a single aggregate value for blank

A

All rows

170
Q

Relational algebra expressions are blank if the expressions operate on the same tables and generate the same result.

A

Equivalent

171
Q

A blank converts an SQL query into a sequence of low-level database actions, called the blank

A

Query optimizer
Query execution plan

172
Q

The blank specifies precisely how to process an SQL statement. A blank is similar to a programming language compiler.

A

The query execution plan
A query optimizer

173
Q

Query optimizers use equivalent expressions to optimize query execution. The query optimizer performs what five steps:

A

1) Converts a query to a relational algebra expression.

2) Generates equivalent expressions.

3) Estimates the ‘cost’ of each operation of each expression.

4) Determines the optimal expression with the lowest total cost.

5) Converts the optimal expression into a query execution plan.

174
Q

The blank of an operation is a numeric estimate of processing time.

A

Cost

175
Q

The cost estimate usually combines both blank and blank in a single measure.

A

storage media access and computation time