Basics Flashcards
What are the different data types that can be stored in a database?
Integer Decimal Text CHAR VARCHAR DATE TIME Datetime Boolean
What does SELECT * mean?
Select all columns
How do you select columns from a table?
SELECT NAME, NAME2 FROM CUSTOMER;
Is a semicolon optional or mandatory?
Option, but if you want to run multiple queries at once it is necessary?
Is select a write command?
No
When importing multiple columns do you add a comma after the last column name?
No
How do you add a new column?
SELECT COL1 * 1.05 AS COL2 FROM TABLE;
Can you use spaces in column names?
No - use an underscore
How do you add comments?
– or */ for multiline comments
How do you concatenate text?
||
How do you filter for only particular rows?
WHERE
What are operators?
=
!=
>=
<=
= or == for where?
=
How do you get a range of dates using a where statement?
between
Is between inclusive or exclusive?
Inclusive
What are the wilcards?
% and _
What is the difference between % and _
% is any number of characters and _ is one
How are booleans stored?
0 false
1 true
Do you have to use = 1 for where clauses where you want true?
No but you do for false
How do you select null values?
is null
is not null
Are null values included in where clauses?
No so you must specific with an or statement
How can you filter data more efficiently than writing multiple or statements?
where ZYD IN (2010,2011,2012);
How do you filter on text?
WHERE code = ‘dfdsfsdf’
put the search term in single quotes
Can you use where and in on text values?
Yes - but they have to be in single quotes
How do you filter on the length of the values?
WHERE length(report_code) != 6
How do you search using wildcards?
WHERE report_code LIKE ‘A%’
How do you filter on a boolean?
WHERE hail = 1 AND thunder = 1
What are your options to include null values?
WHERE precipitation IS NULL OR precipitation <= 0
or
coalesce(precipitation,0) <= 0
What order should statements be made?
SELECT FROM WHERE GROUP BY ORDER BY HAVING
How do you get the number of records?
SELECT COUNT(*) as record_count FROM station_data
What do you have to have in group by?
In select you have to have the column that you are grouping on