SQL Flashcards

1
Q

What is a SQL Subquery?

A

A subquery (also called an inner or nested query) is a query within another query.

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

Can a subquery be nested in a SELECT clause?

A

Yes. Subqueries are usually nested in the SELECT, FROM, and/or WHERE clauses.

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

Can a subquery be nested in a SET query?

A

Subqueries can’t be nested in SET queries.

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

What is a SET command used for?

A

The SET command is used with UPDATE to specify which columns and values that should be updated in a table.

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

What do you use to assign a value that isn’t NULL to a declared variable?

A

The SET statement that assigns a value to the variable returns a single value. When initializing multiple variables, use a separate SET statement for each local variable.

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

Can you use comparison operators such as >, <, or = within queries?

A

Yes, comparison operators such as >,>, or = help you compare data in subqueries. You can also use multiple row operators, including IN, ANY, or ALL.

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

What is the statement containing a subquery called?

A

Outer query or outer select. Subqueries are nested within these statements, called inner queries or inner select.

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

Does the parent query execute before its inner query?

A

The innermost query executes first. Its parent query executes last so it can use the results returned by inner queries.
-You can specify up to 16 subqueries within a single SQL statement, and you can specify subqueries within a subquery.
-Subqueries run from last to first within the main SQL statement in which they appear.

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

True or False: Subqueries don’t have to be enclosed within parentheses.

A

False. Parentheses are used to mark the beginning and end of a subquery.

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

Can a subquery have more than one column specified in the SELECT clause?

A

Specify only one column or expression in a subquery unless you use IN, ANY, ALL, or EXISTS.

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

What is not allowed in a subquery?
https://www.ibm.com/docs/en/qmf/11.2.1?topic=ddfmtuss-creating-subquery-retrieve-data-from-more-than-one-table

A

-A subquery cannot contain a BETWEEN or LIKE clause.
-A subquery cannot contain an ORDER BY clause.
-A subquery in an UPDATE statement cannot retrieve data from the same table in which data is to be updated.
-A subquery in a DELETE statement cannot retrieve data from the same table in which data is to be deleted.

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

LEFT function does…

A

Returns a set number of characters from the left side of a text string.

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

LEN function does…

A

Returns the length of a string of text by counting the number of chars it contains.

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

FIND function does…

A

Locate specific characters in a string.

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

RIGHT function does…

A

Return a set number of chars from the right side of a text string.

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