SQL Flashcards
From Facebook Blueprint SQL lessons (not included in the MarSci Study Guide)
Name this type of JOIN:
LEFT JOIN
Name this type of JOIN:
FULL OUTER JOIN
Name this type of JOIN:
INNER JOIN
Name this type of JOIN:
RIGHT JOIN
What is the name of the programming language designed to communicate with databases?
SQL
SQL stores data in tables, also known as what?
relational database structures
What SQL query is considered the most basic form?
SELECT
What SQL statement is used to retrieve data from all columns in a table or to retrieve data from specified columns?
SELECT
Fill in the blank: In order to get all all data from a customers table, use the _____ _ _____ query.
SELECT * FROM
Scenario:
There is one table of data called “customers.” We need to get ids, first names, last names, and age from the “customers” table.
What query would we write to do this?
SELECT customer_id, first_name, last_name, customer_age
FROM customers
What SQL clause filters results?
WHERE
Scenario:
There is one table of data called “customers.” We want to get first names and last names from the table, but only of those customers who are less than 35 years old.
What query would we write to do this?
SELECT first_name, last_name
FROM customers
WHERE age < 35
Scenario:
There is one table of data called “customers.” We want to get customer IDs from the table, but only for those who have the last name “Smith.”
What query would we write to do this?
SELECT customers_id
FROM customers
WHERE last_name = ‘Smith’
Fill in the blank: _____ _____ is a SQL query used to sort data
ORDER BY
What SQL query returns results in ascending order by default?
ORDER BY
ORDER BY sorts query results in ascending order by default. What do you add to the statement in order to sort in descending order?
DESC
Scenario:
You have a table of data called “customers.” You want to retrieve a list of all customers by first name and last name, ordered alphabetically by last name.
What query would you write to do this?
SELECT first_name, last_name
FROM customers
ORDER BY last_name
Scenario:
You have a table called “customers.” You want to pull a list of customers’ last names, customer IDs, and ages. You only want customers under the age of 40 included in the last, and you want it ordered alphabetically by last name.
What query do you write to do this?
SELECT last_name, customer_id, ages
FROM customers
WHERE age < 40
ORDER BY last_name
Scenario:
You have a table called “customers.” You want to pull all the data in the table, sorted by age in descending order.
What query do you write to do this?
SELECT *
FROM customers
ORDER BY age DESC
What SQL command is used to only pull a small subset of data?
LIMIT
What SQL command would you use to test out a query without pulling a large set of data?
LIMIT
What are the three main data types in SQL?
INTEGER, TEXT, and BOOLEAN
What category of SQL commands allow you to use math functions with your data?
Aggregators
What SQL aggregator is used to find out how many records are in a data set?
COUNT