Matt's SQL Reference

index

Data Manipulation Language (DML) Statements

CommandDescriptionSyntaxExample
Select Retrieves data from the database select columns
from tables
where conditions
order by columns
select last_name
from customers
where age < 40
order by last_name;
select function(column)
from tables
group by column
select department, count(last_name)
from customers
group by department;
select columns
from table aliase
where conditions;
select c.last_name, d.suite
from customers c, departments d
where c.department=d.department;
Insert Adds a new row into a table, with the specified values for each column insert into tablename
values (value1, value2, value3);
insert into customers
values ('Jones', 'Mary', '35');
insert into tablename (column1, column2)
values (value1, value2);
insert into customers
('last_name','first_name') values ('Smith', 'Bill');
insert into tablename select * from tablename2; insert into customers
select * from oldcustomers;
Delete Deletes a row or rows from the table which match the specified criteria delete from tablename
where condition;
delete from customers where employment_status='terminated'i;
Update Changes a row or rows from the table which match the specified criteria update tablename
set column1=value1, column2=value2
where condition;
update customers
set middle_name=null
where middle_name='none';
Commit Commits last set of changes to the database commit; commit;
Rollback Abandons last set of changes rollback; rollback;

Last updated Please report any problems or comments to matt@mindflip.com