Sei sulla pagina 1di 1

COMMAND FUNCTION

AS Used to rename a column. Most helpful when you are calculating something in your select statement.
(note: if you are using more than one word or want mixed case use “”)

SELECT (hours_worked * hourly_wage) AS “Salary” FROM employee


AVG, MAX, These are 3 of the 4 – Aggregate functions. You can use them in the select statement, group by statement
MIN, SUM and having statement

SELECT AVG(price) FROM products


COUNT This is the fourth aggregate function. You use this to count the number of rows that meet some criteria.
When you use the * with count it counts each row, when you put an attribute in the () it counts

SELECT COUNT(*) FROM employee WHERE state = ‘MA’


DELETE This is used to delete a row in your table

DELETE FROM employee WHERE state = ‘MA’


DISTINCT This removes duplicates in your output.

SELECT DISTINCT state FROM employee


IN, NOT IN This compares a value to a list of other values. It is very helpful when doing subqueries and you do not
know how many values will be returned.

SELECT employee_id
FROM employee WHERE position IN
(SELECT position FROM employee WHERE salary > 50000)
INSERT Used to insert data into a table. Note: If you are not adding something to every column you can either list
out the attribute names you have data for and then the data you want in them, OR put in a space holder by
using ‘’. Dates are always in the following format and they use single quotes ’01-JAN-1999’

INSERT INTO employee


VALUES (‘Fred”,’’,’Flinstone)
LIKE This is used for pattern matching. % is used for any number of characters in a string and _ is used for a
single character. When you use Like you MUST have your capitalization correct for a match to be found.

Select employee_fname FROM employee WHERE employee_fname LIKE ‘%fred%’ or employee_fname


LIKE ‘%Fred%’
ORDER BY This puts your columns in order. If you want to order your output by more than one column put the first
column first in the order by statement and the second column next.

SELECT employee_lname, salary


FROM employee
ORDER BY salary, employee_lname
SELECT ALL SQL queries start with SELECT
If you need to output a calculated or derived value you can do that in the select statement

SELECT employee_fname, (salary*hours_worked) AS “Pay Check”


FROM employee
UPDATE This is used to modify the data in your table.

UPDATE shr SET shrqty = shrqty*1.1


WHERE shrfirm = 'Nigerian Geese';
WHERE This is used to restricting your out put based on something

SELECT employee_lname
FROM employee
WHERE salary > 50000

Potrebbero piacerti anche