Join two or more conditions in the WHERE clause, at least condition must be true
Back
<> or ! =
Front
SQL operator for not equal to
Back
IN
Front
operator that tests whether or not a value (stated before the keyword) is part of the list of values provided after the keyword; replaces compound operator need to use AND/OR
is a list of columns, data types, or values that are passed to a clause as an argument
Back
ORDER BY
Front
optional clause to sort
Back
AND
Front
Joins two or more conditions in the WHERE clause; both conditions must be true
Back
ASC
Front
sort by ascending (smallest on top)
Back
DESC
Front
sort by descending (largest on top)
Back
+
Front
used for addition
Back
-
Front
used for subtraction
Back
Semicolon ;
Front
Goes at the end of a SQL statement so it will execute
Back
SELECT
Front
Select columns
Back
MAX
Front
returns largest value in a column
Back
SELECT name FROM celebs;
Front
SELECT statements are used to fetch data from a database. Here, SELECT returns all data in the name column of the celebs table.
1. SELECT is a clause that indicates that the statement is a query. You will use SELECT every time you query data from a database.
2. name specifies the column to query data from.
3. FROM celebs specifies the name of the table to query data from. In this statement, data is queried from the celebs table.
Back
ALL
Front
selects all data
Back
BETWEEN
Front
selects all keyword within a range; Used in WHERE statement
Back
WHERE
Front
create a condition from a table
Back
*
Front
Selects all columns to return
Back
___ perform specific tasks in SQL. By convention, __ are written in capital letters. ___ can also be referred to as commands. ex) CREATE TABLE
Front
Clauses
Back
()
Front
Use these types of brackets around conditions to make code easier to read
Back
*
Front
used for multiplication
Back
;
Front
Indicates SQL Statement is Complete
Back
Update the table to include Taylor Swift's twitter handle. In the code editor type:
Front
UPDATE celebs
SET twitter_handle = '@taylorswift13'
WHERE id = 4;
SELECT * FROM celebs;
1 is an integer that will be inserted into the id column
'Micheal Fasbander' is text that will be inserted into the name column
38 is an integer that will be inserted into the age column
Back
CREATE TABLE celebs (id INTEGER, name TEXT, age INTEGER);
Front
1. CREATE TABLE is a clause that tells SQL you want to create a new table.
2. celebs is the name of the table.
3. (id INTEGER, name TEXT, age INTEGER) is a list of parameters defining each column in the table and its data type.
Back
'%ITEM%'
Front
Contains the following word, use with LIKE in WHERE clause
Back
' '
Front
Used around text strings for conditions for easier code reading and machine understanding
Back
AVG
Front
returns the average value in column
Back
COUNT
Front
returns the count of values in a column
Back
HAVING
Front
GROUP BY clause:
Satisfies a condition in "quotes", used for COUNT or plural clauses
Back
How to run a query to see the result?
Front
SELECT * FROM celebs;d
Back
DISTINCT
Front
selects unique records, discards duplicate records
Back
SUM
Front
returns the sum of values in a column
Back
ALTER TABLE celebs ADD COLUMN twitter_handle TEXT;
Front
Add a new column 'twitter_handle' to the table in TEXT format
Back
MIN
Front
returns smallest value in a column
Back
NOT BETWEEN
Front
To display the keyword outside the range
Back
=
Front
SQL operator for equal
Back
SELECT name FROM celebs;
Front
only name column shows from celebs table
Back
PRO%
Front
used for what a command starts with, located in LIKE for WHERE clause
Back
To view the row you just created, under the INSERT statement type
Front
SELECT * FROM celebs;
Back
LIKE
Front
SQL operator for string comparison test, used in where clause
Back
NOT IN
Front
will exclude keywords from a list
Back
Section 2
(50 cards)
ROUND(x)
Front
returns the value of x rounded to the nearest whole integer
Back
Case SenSiTive
Front
SQL is NoT Case Sensitive
Back
UPDATE, set age= age+1 where firstname="Mary"
Front
Clause used with UPDATE where you make an update to a column and then list a condition
Back
UPDATE
Front
Statement used to update records
Back
WHERE city LIKE '[bsp]%';
or
WHERE city NOT LIKE '[!bsp]%';
Front
lets you find a search with any character beginning that is not the following
Back
date(size)
Front
Date value
Back
LEFT JOIN
Front
Return all rows from the left table, and the matched rows from the right table
Back
_
Front
wildcard used to substitute for any single character, multiple can be combined together
Back
value (1, 2, 3)
Front
Used to add data with the INSERT INTO function
Back
WHERE city LIKE '[a-c]%';
Front
lets you find a search with any character in a range
Back
varchar(size)
Front
Variable-length character string. Max size is specified in parenthesis.
Back
CONCAT()
Front
Combines text together
Back
set
Front
Command used to make updates to a table
Back
DELETE, where
Front
statement to remove rows from a table
Back
ALTER [Table, Database]
Front
modifies a table/database
Back
WHERE city LIKE '[bsp]%';
Front
lets you select to begin with any of the following characters
Back
SQL Injection 2
Front
uName = getRequestString("UserName");
uPass = getRequestString("UserPass");
sql = "SELECT * FROM Users WHERE Name ='" + uName + "' AND Pass ='" + uPass + "'"
Back
NOT LIKE
Front
used to show what is not contained in the word
Back
Ex. for INNER Join - FROM customers, items
Front
Most common join "equijoin" or where two tables data are being pulled
Back
POWER(x,y)
Front
returns the value of x raised to the power of y
Back
FROM customer_info INNER JOIN purchases
Front
Another option to write inner join
Back
FLOOR(x)
Front
returns the largest integer value that is less than or equal to x
Back
SELECT TOP 2/50 PERCENT
Front
Selects the first 2, or first 50 percent of data from a table
Back
Batch SQL Code
Front
Code statement;
Code Statement2;
Using semicolons allows multiple statements
Back
number(size, d)
Front
Number value with a maximum number of digits of "size" total, with a maximum number of "d" digits to the right of the decimal.
Back
FULL OUTER JOIN or FULL JOIN
Front
Adds columns from one table to another by way of a join
Back
30 characters
Front
Maximum number of characters allowed for a SQL statement
Back
Primary Key
Front
A combination of a NOT NULL and UNIQUE. Ensures that a column (or combination of two or more columns) have an unique identity which helps to find a particular record in a table more easily and quickly
Back
Address+
Front
Character allowed as a space for when combining phrases together
Back
char(size)
Front
Fixed-length character string. Size is specified in parenthesis. Max 255 bytes.
Back
INSERT INTO
Front
Add Columns or data to a table
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
Back
INNER JOIN, ON
Front
Returns all rows when there is at least one match in BOTH tables
Back
SIGN(x)
Front
returns the sign of input x as -1, 0, or 1 (negative, zero, or positive respectively)
Back
purchases.customer_info
Front
nomenclature used for naming tables when joins for multiple tables is present
Back
Example Between Statements
Front
WHERE ProductName BETWEEN 'C' AND 'M';
BETWEEN #07/04/1996# AND #07/09/1996#;
Back
Not Null
Front
Constraint that specifics a column cannot be empty
returns the smallest integer value that is greater than or equal to x
Back
DROP table "tablename"
Front
Delete a table to start from beginning
Back
number(size)
Front
Number value with a max number of column digits specified in parenthesis.
Back
ROUND(x,d)
Front
returns the value of x rounded to the number of decimal places specified by the value d
Back
MOD(x,y)
Front
modulo - returns the integer remainder of x divided by y (same as x%y)
Back
SQRT(x)
Front
returns the square-root value of x
Back
Section 3
(50 cards)
MID()
Front
Extract characters from a text field
Back
____ programming language designed to manipulate and manage data stored in relational databases.
Front
SQL
Back
ALTER TABLE Persons
DROP CONSTRAINT/INDEX uc_PersonID
Front
Drop constraint
Back
SELECT *
INTO newtable
FROM table1
WHERE 1=0;
Front
Create a new empty table
Back
AUTO_INCREMENT
Front
Data type to auto increase the entries for a column in table
Back
CREATE or REPLACE VIEW
Front
Makes a view to see data
Back
LAST()
Front
function that returns the last value
Back
ROUND()
Front
Rounds a numeric field to the number of decimals specified
Back
DESCRIBE
Front
provides context about the columns in a SQL table
Back
DATE()
Front
Extracts the date part of a date or date/time expression
Back
____ creates a new table.
Front
CREATE TABLE creates a new table.
Back
REFERENCES
Front
points to a different column
Back
ISNULL(), NVL(), IFNULL(), COALESCE()
Front
function to specify how we want to treat NULL Values
Back
TRUNCATE TABLE
Front
delete data in table, not table
Back
___ is a condition in SQL that returns true when the value is NULL and false otherwise.
Front
IS NULL
Back
TO_DATE ( String, [Format], [Optional Setting] )
Front
Converts a Date to a string
Back
FIRST() or TOP 1 + ASC/DESC
Front
function that returns the first value
Back
How dates work
Front
select User.name, User.phone_num, max(UserHistory.date)
from User, UserHistory
where User.user_id = UserHistory.user_id
and UserHistory.action = 'logged_on'
and UserHistory.date >= date_sub(curdate(), interval 30 day)
group by (User.user_id);
Back
Unique
Front
Ensures that each row for a column must have a unique value
Back
UCASE()
Front
function that Converts a field to upper case
Back
LCASE()
Front
function that Converts a field to lower case
Back
INITCAP
Front
returns first character of each word upper case
Back
UNION ALL
Front
Combine both tables and show all duplicates
Back
DATE_SUB()
Front
Subtracts a specified time interval from a date
Back
Default 'Food'
Front
Specifies a default value when specified none for this column
ALTER TABLE Persons
ADD CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)
ALTER TABLE Persons
ADD UNIQUE (P_Id)
Front
Add constraint
Back
NOW()
Front
Returns the current date and time
Back
column IS NULL;
column IS NOT NULL;
Front
query used to search for null values
Back
TRANSLATE
Front
function that let's you change how the context is written
Back
CURDATE()
Front
Returns to the current date
Back
Check
Front
Ensures that the value in a column meets a specific condition
Back
DATE_FORMAT()
Front
Displays date/time data in different formats
Back
Foreign key
Front
Ensure the referential integrity of the data in one table to match values in another table
Back
EXTRACT()
Front
Returns a single part of a date/time
Back
FORMAT()
Front
Formats how a field is to be displayed
Back
Join Two Tables
Front
select Salesperson.Name from Salesperson, Orders where
Salesperson.ID = Orders.salesperson_id and cust_id = '4';
Back
UNION
Front
The UNION operator is used to combine the result-set of two or more SELECT statements.
Back
/ /
Front
Used to comment multiple lines in SQL
Back
RIGHT JOIN
Front
Return all rows from the right table, and the matched rows from the left table
Back
CURTIME()
Front
Returns the current time
Back
____ is a string of characters that the database recognizes as a valid command.
Front
A statement
Back
SELECT INTO
Front
statement selects data from one table and inserts it into a new table.
SELECT Customers.CustomerName, Orders.OrderID
INTO CustomersOrderBackup2013
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID;
Back
DATE_ADD()
Front
Adds a specified time interval to a date
Back
|
Front
Default headsep character in SQL plus
Back
CREATE SEQUENCE [name] STARTS WITH [num] ... INCREMENT BY [num]
Front
Creates a sequence with increments
Back
Insert Rows
Front
insert into highAchiever (name, age)
(select name, age from salesperson where salary > 100000);
Back
DUAL table
Front
One row and one column
Back
DATEDIFF()
Front
Returns the number of days between two dates
Back
Section 4
(18 cards)
A ___ is a set of data values of a particular type. Here id, name, and age are each
---
Front
column
Back
___ deletes rows from a table.
Front
DELETE FROM
Back
WHERE
Front
Clause that filters
SELECT * FROM movies WHERE imdb_rating > 8;
clause that indicates you want to filter the result set to include only rows where the following condition is true.
Back
____ queries data from a table
Front
SELECT
Back
AS
Front
renaming, AS tot_dollar #rename col as tot_dollar
Back
Return empty values
Front
select distinct u.user_id
from User as u
left join UserHistory as uh on u.user_id=uh.user_id
where uh.user_id is null
Back
SELECT DISTINCT
Front
used to return unique values in the result set. It filters out all duplicate values. Here, the result set lists each genre in the movies table exactly once.
1. SELECT DISTINCT specifies that the statement is going to be a query that returns unique values in the specified column(s)