SQL Flashcards
UNION
combines columns between data sets that have:
1. the same number of columns
2. similar data sets
you have to put the columns in the same order in the SELECT column
Is SQL case sensitive for objects you are calling?
YES! you need to write it exactly as it is in the table
When using group by, does it matter the order you list objects?
Yes! to group by that object first it needs to be listed first
if you want to sort SQL columns what argument do you use?
ORDER BY
How would you filter for even ID numbers only?
WHERE ID % 2 = 0
How to order alphabetically in SQL
ORDER BY (variable name) – it defaults to alphabetical
What can you use to connect to separate select causes?
UNION
In MySQL, what do you use to find the length of a variable?
length()
What is an easy way to find the max and min values of a table without using max or min?
select the first value (order by the variable in question and limit 1) , then use UNION to connect the same items but ORDER BY in desc (to get the last value), again limit 1
how would you find values that started with vowels?
WHERE (value) LIKE ‘a%’ OR ‘e%’ OR ‘I%’ etc
when you are using OR, AND, in a where clause can you just use commas or do you need to be specific
BE SPECIFIC ex:
WHERE (value) LIKE ‘a%’ OR ‘e%’ OR ‘I%’ etc
the OR has to be between each thing even if you want OR for all of them
what is the easiest way to sort for variables that end and start with vowels?
use AND to connect LIKE a% AND %a for the whole list of vowels
what is the easiest way to sort variables so they do not start with vowels?
use NOT LIKE (all the vowels)% connecting them with AND instead of OR
when doing a join, does the name of the table go first or second in the select cause
first! ex: city.name ‘; city is the table, name is the variable
describe a Left join
if we are thinking of a venn diagram, a left join takes all the information from the left table (first table called) then the information that matches the left table from the right table (table 2)