SQL Flashcards

1
Q

T/F: In SQL, if we want to impose a condition at the individual record level, we use the WHERE command. If we want to impose a condition at the group level, we use the HAVING command.

A

True

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

FROM

A

specific table we want to extract from

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

AS

A

renames fields

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

SELECT

A

specifies what we want to view

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

WHERE

A

filters query results (ex: WHERE (SuggestedRetailPrice-StandardCost) > 10 = only output records that have values greater than 10)

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

DISTINCT

A

removes duplicate records

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

ORDER BY

A

orders data in ascending order by default (to order in descending order - include DESC = ORDER BY (SuggestedRetailPrice-Cost) DESC)

  • SQL executes ORDER BY command before SELECT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

SELECT * FROM table_name

A

retrieves all fields from the specified table

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

IN

A

allows you to specify multiple values in a WHERE clause
ex: SELECT * FROM tblCustomers WHERE State IN (‘MA’, ‘NY’)

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

OR

A

used with WHERE to include rows where either condition is true
ex: SELECT * FROM tblCustomers WHERE State (‘MA’ OR ‘NY’)

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

GROUP BY

A

creates aggregate measure based on every record in the table (must use for aggregate functions AVG, SUM)

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

HAVING

A

filters data after aggregation has occurred (must use GROUP BY for this to work)
* processed after WHERE, GROUP BY and aggregation functions

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

Inner Join

A

only joins data that have a match in both tables

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

Left Join

A

brings all left table data + matching data from right table (excludes non-matching right table data)

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

Right join

A

brings all right table data + matching data from left table (excludes non-matching left table data)

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

How many unique products did NWT sell in the first 6 months of 2023?

A

23

17
Q

Choose the line of SQL code that would return one row of data for each distinct category of products sold by NWT. Each row would report the category name and a count of the number of products within that category.

A) SELECT Category, COUNT(ProductCode) FROM tblProducts GROUP By Category

B) SELECT Distinct (Category), Count(ProductCode) FROM tblProducts

C) SELECT COUNT (Category), Count(ProductCode) FROM tblProducts GROUP BY Category

A

A) SELECT Category, COUNT(ProductCode) FROM tblProducts GROUP BY Category