0% found this document useful (0 votes)
11 views

SQL 1

Uploaded by

gujjewarsagar63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views

SQL 1

Uploaded by

gujjewarsagar63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
SQL COMMANDS CHEAT SHEET SQL Commands The commands in SQL are called Queries and they are of two types: e Data Definition Query: The statements which defines the structure of a database, create tables, specify their keys, indexes and soon * Data manipulation queries: : These are the queries which can be edited. — E.g: Select, update and insert operation Command el ALTER TABLE table_name It is used to add columns to Golem §=ADD column_name datatype; | a table in a database SELECT column_namels) It is an aperator that is used FROM table_name to combine two conditions WHERE eolumn_t = value_1 AND column_2 = value_2; SELECT column_name AS ROM table_nam etl nutes) ae COUNT CREATE Iria fey (ele e HAVING SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value_1 AND value_2; SELECT column_name, CASE WHEN condition THEN 'Result_1' WHEN condition THEN 'Resuit_2° ELSE ‘Result_3° END FROM table_name; SELECT COUNT (column_name) FROM table_name; CREATE TABLE table_name ( column_1 datatype, column_2 datatype, column_3 datatype Xi SELECT column_name, COUNT (*) FROM table_name GROUP BY column_name; SELECT column_name, COUNT (*) FROM table_name GROUP BY column_name HAVING COUNT(*) > value; It ls an operator used to filter the result within a certain range It is a statement used to create different outputs inside a SELECT statement It is a function that takes the name of a column as argument and counts the number of rows when the column is not NULL it is used to create a new table in a database and specify the name of the table and columns inside it It ls an clause in SQL used for aggregate functions in collaboration with the SELECT statement it is used in SQL because the WHERE keyword cannot be used in aggregating functions Tiscali INSERT 1S NULLS IS NOT NULL SELECT column_name(s) FROM table_1 JOIN table_2 ON table_1.column_name = table_2.column_name; INSERT INTO table_name (column_1, column_2, column _3) VALUES (value_1, ‘value_2', value_3); SELECT column_name(s) FROM table_name WHERE column_name IS NULL; SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern; SELECT column_name(s) FROM table_name LIMIT number; SELECT MAX(column_name) FROM table_name; SELECT MIN(column_name) FROM table_name; [ida] eld It is used to combine rows from different tables if the Jain condition goes TRUE It is used to add new rows to a table lt is a operator used with the WHERE clause to check for the empty values It is an special operator used with the WHERE clause to search for a specific pattern ina column It is a clause to specify the maximum number of rows the result set must have It is a function that takes number of columns as an argument and return the largest value among them It is a function that takes number of columns as an argument and return the smallest value among, them fel Pls ac) e OUTER JOIN SELECT oli Lag SELECT column_name FROM table_name WHERE column_name = value _1 OR column_name = value_ SELECT column_name FROM table_name ORDER BY column_name ASC | DESC; SELECT column_name(s) FROM table_1 LEFT JOIN table_2 ON table_1.column_name = table_2.columm_name: SELECT ROUND(column_ name,integer) FROM table_name; SELECT DISTINCT column_ name FROM table_name; SELECT SUM(column_name) FROM table_name; it is an operator that is used to filter the result set to contain only the rows where either condition is TRUE itis a clause used to sort the result set by a particular column either numerically or alphabetically It is sued to combine rows from different tables even if the condition is NOT TRUE It is a function that takes the column name and a integer as an argument, and rounds the values ina column to the number of decimal places specified by an integer It is a statement that is used to fetch data froma database itis used to specify that the statement is a query which returns unique values in specified columns It is function used to return sum of values from a particular column UPDATE table_name It is used to edit rows ina SET some_column = some_ table value WHERE some_column = some_value; UPDATE SELECT column_namet(s) It is a clause used to filter FROM table_name the result set to include WHERE column_name the rows which where the operator value; condition is TRUE WITH temporary_name AS ( It Is used to store the result SELECT * of a particular query in a FROM table_name) temporary table using an SELECT * alias FROM temporary_name WHERE column_name operato| value; DELETE FROM table_name it is used to remove the WHERE some_column = rows from a table some_value; SELECT AVG(column_name) It is used to aggregate a FROM table_name; numeric column and return its average ee ese ace Muy UE eu es ie recat ier CER Met Cenc Mc aes SELECT cl, c2 Saas ana elias FROM t1 INNER JOIN t2 on condition To select the data in Column ct Select column c1 and c2 from table from table t t1 and perform an inner join between tl and t2 eT UE Aru eich e cig UPL PEG ee sein ltd Cease aera) Cer OMe cme SELECT cl, c2 ese ee] ed FROM tl LEFT JOIN t2 on condition er ae eeu eel ued Select column ¢1 and c2 from table from table t t1 and perform a left join between t1 and t2 SELECT cl, c2 FROM t1 RIGHT JOIN t2 on condition Select column ci and c2 from table t1 and perform a right join between t1 and t2 naa OL ee Ral bt Rag tie eee Riese na 10S a a8) a SELECT cl, c2 FROM tl ORDER BY cl ASC (DESC) FULL OUTER JOIN 2 on condition Br eee re me rea a Select column cl and c2 from table ce eae Lats tl and perform a full outer join Cet tue between tl and t2 SELECT c1 FROM t SELECT cl, c2 FROM tI ele] t a-ha ele CROSS JOIN t2 offset Select column c1 and c2 from table BC Ra er eee ee ial | t1 and produce a Cartesian product Gea} of rows in a table SELECT c1, aggregate(c2) eres SELECT cl, c2 FROM t1, t2 Select column c1 and c2 from table t1 and produce a Cartesian product of rows in a table GROUP BY c1 PCP eee eae etd ast Pee Ch ale PU UCC amie ald Cre eRe MeL Cee til Me Tl jane igs cc (24) FROMt Cees eerie) Group rows using an aggregate a UCR eli or) Petree ih cased SELECT cl, c2 FROM t1 A INNER JOIN t2 B on condition Select column ci and c2 from table {1 and join it to itself using INNER JOIN clause ntelliPaat FURTHERMORE: SQL Developer, SQL DBA Training Masters Program

You might also like