Basics Flashcards

(78 cards)

1
Q

What are the different data types that can be stored in a database?

A
Integer
Decimal
Text
CHAR
VARCHAR
DATE
TIME
Datetime
Boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does SELECT * mean?

A

Select all columns

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

How do you select columns from a table?

A

SELECT NAME, NAME2 FROM CUSTOMER;

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

Is a semicolon optional or mandatory?

A

Option, but if you want to run multiple queries at once it is necessary?

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

Is select a write command?

A

No

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

When importing multiple columns do you add a comma after the last column name?

A

No

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

How do you add a new column?

A

SELECT COL1 * 1.05 AS COL2 FROM TABLE;

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

Can you use spaces in column names?

A

No - use an underscore

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

How do you add comments?

A

– or */ for multiline comments

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

How do you concatenate text?

A

||

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

How do you filter for only particular rows?

A

WHERE

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

What are operators?

A

=
!=
>=
<=

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

= or == for where?

A

=

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

How do you get a range of dates using a where statement?

A

between

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

Is between inclusive or exclusive?

A

Inclusive

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

What are the wilcards?

A

% and _

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

What is the difference between % and _

A

% is any number of characters and _ is one

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

How are booleans stored?

A

0 false

1 true

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

Do you have to use = 1 for where clauses where you want true?

A

No but you do for false

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

How do you select null values?

A

is null

is not null

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

Are null values included in where clauses?

A

No so you must specific with an or statement

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

How can you filter data more efficiently than writing multiple or statements?

A

where ZYD IN (2010,2011,2012);

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

How do you filter on text?

A

WHERE code = ‘dfdsfsdf’

put the search term in single quotes

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

Can you use where and in on text values?

A

Yes - but they have to be in single quotes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you filter on the length of the values?
WHERE length(report_code) != 6
26
How do you search using wildcards?
WHERE report_code LIKE 'A%'
27
How do you filter on a boolean?
WHERE hail = 1 AND thunder = 1
28
What are your options to include null values?
WHERE precipitation IS NULL OR precipitation <= 0 or coalesce(precipitation,0) <= 0
29
What order should statements be made?
``` SELECT FROM WHERE GROUP BY ORDER BY HAVING ```
30
How do you get the number of records?
``` SELECT COUNT(*) as record_count FROM station_data ```
31
What do you have to have in group by?
In select you have to have the column that you are grouping on
32
How do you sort?
ORDER BY year, month
33
What is the default sort order?
ascending
34
How do you get a descending sort?
ORDER BY year DESC, month
35
What is the difference between count(*) and count(preciptitation?)
Count referring to a column will ignore null values
36
Do you have to use as alias when using an aggregate function?
No but it makes life easier
37
SELECT COUNT(*) as record_count or SELECT COUNT(*)
Select count as record_count
38
What is the average code?
AVG(temperature)
39
How do you get to 2 decimal places?
round(avg(temperature),2)
40
What are the aggregate functions?
AVG MIN MAX SUM
41
Can you use where on aggregate values?
No use having
42
What does where filter on?
Records
43
How do you assign another value based on certain conditions?
Case statement
44
What is the case structure?
CASE WHEN THEN ELSE END as alias
45
What is the indent structure of case?
WHEN THEN and ELSE are indented
46
Can you group on a case expression?
Yes
47
When selecting using a case expression do you need a comma at the end?
Yes
48
How do you count the records using the case expression
Count(*) not count(cat)
49
Do you have to have a comma at the end of the case expression?
Yes
50
How do you get two columns of different values of T/F for a different variable without using a join?
Use a case statement; | SUM(CASE WHEN precipitation = 1 THEN precipitation ELSE NULL END) as tornado_precipt
51
How do you do an inner join?
FROM CUSTOMER INNER JOIN CUSTOMER_ORDER | ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID
52
Where do you do an inner join?
In the from statement
53
What comes first when specifying what table a column should come from?
table.column
54
What do you do for a left join?
FROM CUSTOMER LEFT JOIN CUSTOMER_ORDER | ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID
55
Which table is the left table in a left join?
The first one
56
How do you use a left join to find customers who have no orders?
SELECT CUSTOMER.CUSTOMER_ID, NAME AS CUSTOMER_NAME FROM CUSTOMER LEFT JOIN CUSTOMER_ORDER ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID WHERE ORDER_ID IS NULL
57
How do you join multiple tables?
Do multiple joins: FROM CUSTOMER INNER JOIN CUSTOMER_ORDER ON CUSTOMER_ORDER.CUSTOMER_ID = CUSTOMER.CUSTOMER_ID INNER JOIN PRODUCT ON CUSTOMER_ORDER.PRODUCT_ID = PRODUCT.PRODUCT_ID
58
How do you create a table?
``` CREATE TABLE NAME ( COMPANY_ID INTEGER PRIMARY KEY COLNAME TEXT NOT NULL DESCRIPTION VARCHAR(10) PRIMARY_ATT_ID ``` ``` FOREIGN KEY (PRIMARY_ATT_ID) REFERENCES ATTENDEE(ATTENDEE_ID) ); ```
59
How do you assign a primary key?
COLNAME INTEGER PRIMARY KEY
60
How do you assign a foreign key?
FOREIGN KEY (NAME) REFERENCES OTHER_TABLE(NAMEINOTHERTABLE)
61
When creating a table how do you make a column mandatory?
NOT NULL
62
Does each table require a primary key?
Yes
63
How do you autogenerate a value?
AUTOINCREMENT
64
Do you have to have a comma after the column names in create a table?
yes
65
Can you specify a default value when creating a table?
DEFAULT(VALUE)
66
Can you have more than 2 foreign keys?
Yes
67
Where do the columns go between the foreign keys?
After the end of the last column name and no further ones
68
Do you indent on create table?
Yes
69
If you are creating different tables in the same query do you need semicolons?
Yes
70
How do you create a view?
CREATE VIEW NAME AS .....
71
How do you add a record?
INSERT INTO ATTENDEE (FIRST_NAME, LAST_NAME) | VALUES ('THOMAS', 'NIELD')
72
When inserting records into a database, is it values 'jon' or values('jon')
values('jon')
73
Can you insert multiple records at a time?
Yes | values('j','k'),('l','m'),('k','j')
74
Can you insert record that has a foreign key that does not exist as a primary key in the original table?
No
75
How do you round down?
FLOOR
76
How do you round up?
CEIL()
77
How do you give a subquery an alias?
Indent, and then AS WHATEVER after the parenteses (SELECT NAME, MONTHS, SALARY, MONTHS * SALARY AS EARNINGS FROM EMPLOYEE ORDER BY EARNINGS DESC) AS EARNINGS
78
How do you return only the first row?
LIMIT 1