Introduction to Select Statements Flashcards

1
Q

What is a SELECT statement?

A

A SELECT statement retrieves columns of data from one or more tables or views.

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

What are some ways you can use the SELECT statement?

A

It can list all columns within a table. It can list specific columns in a table. You can use the SELECT statement to list specific columns and then filter rows with the WHERE statement. You can display columns and list data from multiple tables using a JOIN statement.

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

What order will your columns be displayed in your table?

A

The order that you list them out in your SELECT statement.

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

If your column has a space in it, like a column that says “First Name,” how would you write it in your SELECT statement?

A

You would use brackets.

SELECT
VersionDate
, [First Name]

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

How do you display all the columns in a table in your result set?

A

SELECT *

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

Why is it not good practice to use SELECT *?

A

Because it decreases performance. It’s better to explicitly define your columns in the SELECT statement.

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

What is a SQL statement?

A

It is a complete command that performs an action on a database and can include multiple clauses.

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

How do you list the Table Name Syntax in the FROM clause?

A

server.database.schema.object

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

What does the FROM clause identify?

A

The table where data will be pulled. If you are pulling from multiple tables, you will identify the relationships in the FROM clause.

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

What is an SQL Clause?

A

It is a part of a SQL statement that specifies a condition or operation. For example, the FROM clause.

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

What does the WHERE clause do?

A

It filters the rows of a result set. It can’t filter from tables not listed in the FROM clause. However, it can filter columns not present in the SELECT clause.

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

What does a simple WHERE condition consist of?

A

It consists of a column, an operator, and a value.

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

When do you need to enclose a value in single quotes in a WHERE clause?

A

Text and Dates entries need quotes.

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

Which clause type can you compare columns against each other?

A

In the WHERE clause. WHERE StartDate = EndDate

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

What is the not equal operator in a WHERE statement?

A

<>

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

What is a Greater Than operator in a WHERE statement?

A

>

12
Q

What is a Greater Than or Equal Operator in a WHERE statement?

A

> =

13
Q

What is a Less tHAN or Equal operator in a WHERE statement?

A

<=

14
Q

What operators string together multiple search conditions?

A

AND and OR

15
Q

How do you prioritize the order search conditions are executed in the WHERE clause?

A

Using parenthesis!

16
Q

Which is executed first. The search conditions in the parenthesis or the ones not in the parenthesis in the WHERE clause multiple search condition search statement?

A

The parenthesis is ordered first!

17
Q

What does the ORDER By Clause do?

A

It sorts the order of rows in the record set.

18
Q

How do you separate multiple order by clauses?

A

Using a comma. Example ORDER BY Country, State, LastName

19
Q

How do you sort information in ascending or descending order?

A

Use ASC and DESC keywords after each column you want sorted.

For example

ORDER BY
Country DESC, State DESC, LastName ASC

20
Q

Why might you use a table alias?

A

You can use a table alias to tell SQL which which table to refer to if there are columns in multiple tables that have the same name.

21
Q

What’s the order that the SELECT statement is executed in.

A

FROM
WHERE
SELECT
ORDER BY

22
Q

What clause can you not use alias names? Why is that?

A

WHERE clause because it is executed before the SELECT clause.

23
Q

What does the DISTINCT keyword do and how do you use it?

A

DISTINCT eliminates duplicates in a column. You will use it with the SELECT statement. If there are multiple columns in your result set, the entire row must be a duplicate for it to be removed

24
Q

What does SELECT TOP Do?

A

It limits the number of rows returned.

25
Q

How do you limit the percentage of results?

A

You can use the PERCENT keyword. Ex. SELECT TOP 10 PERCENT

26
Q

What do you do if you have results that are tied and want to see all the final results with that information?

A

Use SELECT TOP WITH TIES

27
Q
A