SQL Commands Flashcards

1
Q

What does the “AS” command do?

A

allows you to rename a column or table

SELECT column_name AS ‘alias’ from table_name;

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

What does AVG do?

A
Returns the average of the numeric value
SELECT AVG(column_name_ from table_name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the BETWEEN command do?

A

Filters the result between certain range

SELECT column_name from table_name WHERE column_name BETWEEN value_1 and value_2

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

What does the CASE command do?

A

If-then logic to create new variables

SELECT column_name,
CASE
WHEN condition THEN 'Result_1'
WHEN condition THEN 'Result_2'
ELSE 'Result_3'
END
FROM table_name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

COUNT

A

Count non-null rows in a column

SELECT COUNT(column_name_ from table_name;

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

GROUP BY

A

Aggregate function
Organizes the output into different groups

SELECT column_name
FROM table_name
GROUP BY column_name

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

HAVING

A

Is “WHERE” with aggregate functions

SELECT column_name, COUNT()
FROM table_name
GROUP BY column_name
HAVING COUNT(
) > value;

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

Website with these commands

A

https://www.codecademy.com/articles/sql-commands

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

Inner Join

A

Combine different rows from different tables if the JOIN condition is true

SELECT column_name
FROM table_name1
JOIN table_2
ON table_1.column_name = table_2.column_name;

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

IS NULL / IS NOT NULL

A

Used with WHERE clause to test for empty values

SELECT column_name
FROM table_name
WHERE column_name IS NOT NULL

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

LIKE

A

Special operator used with the WHERE caluse to search for a specific pattern in a column

SELECT column_name
FROM table_name
WHERE column_name LIKE %pulse%

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

LIMIT

A

Clause that lets you specific the maximum number of rows the result set will have

SELECT column_name
FROM table_name
LIMIT number;

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

MAX

A

function that returns the largest value in a column

SELECT MAX(column_name)
FROM table_name;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

MIN

A

Function that returns the smallest value in a column

SELECT MIN(column_name)
FROM table_name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

OR

A

Operator that filters the results set to only include where where either condition is true

SELECT column_name
FROM table_name
WHERE column_name = value_1
OR column_name2=value_2

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

ORDER BY

A

Clause that allows you to order the results by a particular column in ascending or descending order

SELECT column_name
FROM table_name
ORDER BY column_name ASC | DESC

17
Q

LEFT JOIN

A

Combine rows from different tables even if the join condition is not met.
With left join, all of the rows on the left table is returned.

SELECT column_name
FROM table_name
LEFT JOIN table_2
ON table_1.column_name = table_2.column_name

18
Q

RIGHT JOIN

A

Combines rows from different tables even if the join condition is not met.
With right join, all of the rows on the right table are returned. NULL for left table

SELECT column_name
FROM table_1
RIGHT JOIN table_2
ON table_1.column_name = table_2.column_name

19
Q

FULL JOIN

A

Returns all records when there is a match in the left or right table records.

SELECT column_name
FROM table1
FULL JOIN table2
ON table1.column_name = table2.column_name;

20
Q

ROUND

A

Function that rounds the values in a column to the integer specified in the function argument.

SELECT ROUND(column_name, integer)
FROM table_name
21
Q

SELECT DISTINCT

A

specifies that the statement is going to be a query that returns unique values in the specified columns

SELECT DISTINCT column_name
FROM table_name;

22
Q

SUM

A

Function that adds a column

SELECT SUM(column_name) 
FROM table_name
23
Q

Comments in SQL

A

/*

*/

24
Q

How to create subqueries (nested queries, inner queries)

A

SELECT column_name,
(Select AVG(salary) from table_name as NAME from table_name)
FROM table_name

25
Q

Where can you use subqueries?

A

SELECT, FROM, WHERE

Basically anywhere