275 SQL Flashcards

1
Q

A full outer join includes rows that satisfy the join condition, plus

A

Rows in both tables that don’t satisfy the join condition

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

When applying multiple join conditions (i.e. more than one condition which must be true) to an inner join in explicit syntax, the extra conditions can be applied:

A

In the WHERE clause and/or the ON section

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

The basic format for an inner join using explicit syntax is:

A

SELECT … FROM table1 JOIN table2 ON join_condition

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

In most cases, the join condition of an inner join compares the primary key of one table to the ____________________ key of another table.

A

foreign

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

When performing an inner join using implicit join syntax, you should place the join condition(s):

A

In the WHERE clause

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

In a cross join, all of the rows in the first table are joined with…

A

all rows in the second table

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

SELECT v.VendorName AS Vendor, i.InvDate AS Date
FROM Vendors v
JOIN Invoices i ON v.VendorID = i.VendorID;

In this example, “i” is known as…

A

a table alias

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

Correlation names (aka table aliases) can be specified with the option AS keyword to temporarily re-name a table within the scope of the query. When/how is the best practice for using correlation names?

A

When they simplify or clarify the query.

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

Queries combined with UNION must use the same tables to avoid an error.

A

False

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

SELECT VendorName, InvoiceNumber
FROM Invoices i
RIGHT JOIN Vendors v ON i.VendorID = v.VendorID;

If the RIGHT keyword is replaced with the LEFT keyword, the query…

A

keeps unmatched rows in the Invoices tab

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

Specify the correct order in which each of the six SQL clauses must be placed:

A

select> from> where> group by> having> order by

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

What is the ROLLUP operator used for in the GROUP BY clause?

A

To add a summary total for each grouping

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

A select statement that includes aggregate functions is often called_____ query

A

summary

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

expressions coded in the where clause…`

A

can use non-aggregate search conditions but can’t use aggregate search conditions

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

Which of the following is a valid aggregate function in SQL? Check only those that apply.

A

min, avg, sum, count

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

A logical condition comparing against an aggregate function (e.g. COUNT) can be used in:

A

Only the HAVING clause

17
Q

The GROUP BY clause can contain more than one value (separated by commas). In the query below, what does SUM(Salary) represent?

SELECT Department,
State,
SUM(Salary)
FROM EMPLOYEES
GROUP BY Department, State;

A

The salary budget for each combination of department and state

18
Q

The WHERE clause and the HAVING clause can both limit rows in the result set based on logical conditions. What is the difference between the two clauses?

A

HAVING can make comparisons against aggregate functions

19
Q

When applying DISTINCT to the value being calculated in an aggregate function like COUNT, what is the effect?

SELECT COUNT(DISTINCT StreetName)
FROM ADDRESSES;

A

To count only unique values

20
Q

Multiple conditions (connected by logical AND or OR) can only be used in the WHERE clause; they can never be used in the HAVING clause.

21
Q

A subquery is a/an ______________ statement that’s coded within another SQL statement.

22
Q

WHERE clause comparisons against a subquery can use comparison operators (e.g. + > < >= <= etc.). The ANY and SOME keywords can be applied to this type of comparison to match part of the returned set of values. What is the functional difference between ANY and SOME?

A

None of the above; they are equivalent

23
Q

When using a comparison operator (e.g. = > < >= <= etc.) against a subquery, the subquery must return a single value (one row, one column); otherwise an error will result. What is one method to make this type of comparison and avoid the error?

A

Write the subquery using an aggregate calculation

24
Q

Which of the following are true about correlated subqueries when used in WHERE clause conditions? Check only those that apply:

A

When using the same table as the outer query, they require the use of an alias

They refer to a value provided by a column in the outer query

They are executed once for each row processed by the outer query

25
A subquery can be placed in the FROM clause of an outer query to act as a kind of "virtual" table (it must be assigned an alias, and all calculated values must be given labels). What is the name given to this type of subquery?
A derived table
26
Subqueries can be ________________ within other subqueries.
nested
27
Which is true when using a subquery in the SELECT clause of an outer query?
They must return only a single value
27
The following are all valid locations in an SQL query for a subquery. According to the text, which is the most commonly used?
In the WHERE or HAVING clause as a subquery search condition
28
Which of the following is true when using the EXISTS comparison against a subquery in the WHERE clause?
It resolves as true when the subquery returns any rows
29
A subquery can sometimes be restated as...
a join