SQL Cheat Sheet
SQL Cheat Sheet
SELECT Statements INSERT Statements - Entering every field in a record Order of the fields when
SELECT statements are used to query a database and return some values. inserting is important!
INSERT Statements add new records into the database
Specify the fields you want to display: SELECT fieldname1,fieldname2 Specify the tablename to insert into: INSERT INTO Instructor
Name the tables that the fields are in: FROM tablename List the values to be inserted: VALUES(5,’D Thomas’,’1985-11-30’,5)
The criteria for your search: WHERE fieldname1 = ‘value’
Any sort order: ORDER BY fieldname1 ASC/DESC, fieldname2 ASC/DESC ; Example:
INSERT INTO Instructor VALUES (5,‘D Thomas’, ‘1985-11-30’,5);
Example: Example:
SELECT name,age SELECT name,age
INSERT Statements - Only entering values for some fields
FROM pupil WHERE age<18 FROM pupil WHERE age<18 SQL Dates are stored in
Sometimes you may not be adding a value for every single field the format yyyy-mm-dd
ORDER BY name ASC; ORDER BY name DESC, age ASC;
Specify the tablename to insert into: INSERT INTO Instructor
When searching for text values you must use ‘speech marksʻ Specify the fields you are entering data for: (InstructorID,Name)
You can use logical conditions such as AND, OR and NOT to create more complex queries
List the values to be inserted: (5,’D Thomas’)
Example:
DELETE Statements INSERT INTO Instructor(InstructorID,Name) VALUES (5,‘D Thomas’);
DELETE statements delete records from a table
EQUI Joins
An equi join is when two matching fields from related tables are selected (joined) using a key field that is present in both tables.