This document contains a cheatsheet summarizing common SQL statements for selecting data, modifying databases, and creating views. It includes SQL statements for selecting data using conditions, joins, aggregation, and ordering; creating, modifying and deleting tables; and creating, altering, and dropping views. The cheatsheet acts as a quick reference guide for the main clauses and functionality of the SQL language.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
378 views
SQL Cheat Sheet
This document contains a cheatsheet summarizing common SQL statements for selecting data, modifying databases, and creating views. It includes SQL statements for selecting data using conditions, joins, aggregation, and ordering; creating, modifying and deleting tables; and creating, altering, and dropping views. The cheatsheet acts as a quick reference guide for the main clauses and functionality of the SQL language.
SELECT * FROM t SELECT * FROM t SELECT * FROM t1 WHERE c1 [NOT] BETWEEN v1 INNER JOIN t2 ON condition SELECT c1,c2 FROM t AND v2 SELECT * FROM t SELECT c1,c2 FROM t SELECT * FROM t WHERE c1 [NOT ] IN (v1,v2, WHERE conditions WHERE c1 [NOT ] IN (v1,v2,…) SELECT * FROM t1 SELECT c1,c2 FROM t SELECT* FROM t INNER JOIN t2 ON condition WHERE conditions WHERE c1 > v1 AND c1 < v2 WHERE conditions ORDER BY c1 ASC,c2 DESC SELECT * FROM t SELECT * SELECT DISTICT c1,c2 WHERE c1 < v1 OR c1 > v2 FROM t1, t2 FROM t WHERE conditions SELECT * FROM t SELECT c1, aggregate(c2 * c3) WHERE c1 = v1 SELECT * FROM t1 FROM t LEFT JOIN t2 ON conditions GROUP BY c1 SELECT * FROM t WHERE c1 <> v1 SELECT * FROM t1 SELECT c1, aggregate(c2 * c3) RIGHT JOIN t2 ON condition FROM t GROUP BY c1 SQL TABLE STATEMENTS SELECT * FROM t1 HAVING c1 > v1 CREATE TABLE t( FULL OUTER JOIN t2 ON con c1 dt1(l1), SELECT * FROM t1 AS at1 SQL UPDATE DATABASE c2 dt2(l2), INNER JOIN t2 AS at2 ON at ... at2.c2 INSERT INTO t (c1,c2…) ) VALUES (v1,v2…) DROP TABLE t SQL VIEW STATEMENTS INSERT INTO t1 (c1,c2…) SELECT c1,c2… FROM t2 ALTER TABLE t CREATE VIEW vw WHERE conditions ADD COLUMN c dt(l) AS SELECT c1,c2 UPDATE t ALTER TABLE t FROM t SET c1 = v1, c2 = v2,… DROP COLUMN c WHERE conditions ALTER VIEW vw AS DELETE FROM t SQL VIEW STATEMENTS SELECT c1,c2 WHERE conditions CREATE UNIQUE FROM t TRUNCATE TABLE t INDEX idx ON t(c1,c2..) DROP VIEW vw DROP INDEX t.idx
t:table name, c: column name,vw: view name, v: value,dt: data type,l: data type length, at: table alias,aggregate: aggrea function,idx: index name