SQL commands allow users to query and manipulate data. The main commands are SELECT, INSERT, UPDATE, and DELETE. SELECT is used to query data from one or multiple tables and can include functions like COUNT, ROUND, and SUM. JOIN operations combine data from different tables. INSERT adds new rows. GROUP BY groups data and HAVING filters groups.
SQL commands allow users to query and manipulate data. The main commands are SELECT, INSERT, UPDATE, and DELETE. SELECT is used to query data from one or multiple tables and can include functions like COUNT, ROUND, and SUM. JOIN operations combine data from different tables. INSERT adds new rows. GROUP BY groups data and HAVING filters groups.
Commands and syntax for Commands and syntax for querying
Command Syntax Description Command Syntax Description querying data from Single Table data from Multiple Table It is an clause in SQL used SELECT column_name(s) SELECT c1, c2 SELECT column_name, COUNT(*) It is sued to combine rows FROM t1 C H E AT S H E E T for aggregate functions in FROM table_1 SELECT c1 FROM t GROUP BY FROM table_name from different tables even INNER JOIN t2 on condition collaboration with the OUTER JOIN LEFT JOIN table_2 GROUP BY column_name; if the condition is NOT To select the data in Column c1 Select column c1 and c2 from table SELECT statement ON table_1.column_name = TRUE from table t t1 and perform an inner join SQL Commands SELECT column_name, COUNT(*) It is used in SQL because table_2.column_name; between t1 and t2 FROM table_name the WHERE keyword It is a function that takes The commands in SQL are called Queries and they are of two types: HAVING SELECT c1, c2 GROUP BY column_name cannot be used in the column name and a • Data Definition Query: The statements which defines the SELECT * FROM t FROM t1 HAVING COUNT(*) > value; aggregating functions SELECT ROUND(column_name, integer as an argument, structure of a database, create tables, specify their keys, LEFT JOIN t2 on condition SELECT column_name(s) ROUND integer) and rounds the values in a To select all rows and columns Select column c1 and c2 from table indexes and so on FROM table_1 It is used to combine rows FROM table_name; column to the number of from table t t1 and perform a left join between t1 • Data manipulation queries: These are the queries which can INNER JOIN JOIN table_2 from different tables if the decimal places specified by and t2 be edited. ON table_1.column_name = Join condition goes TRUE an integer SELECT c1, c2 E.g.: Select, update and insert operation table_2.column_name; It is a statement that is SELECT c1 FROM t FROM t1 SELECT column_name INSERT INTO table_name SELECT used to fetch data from a WHERE c1 = ‘test’ RIGHT JOIN t2 on condition Command Syntax Description (column_1, column_2, column_3) It is used to add new rows FROM table_name; To select data in column c1 from Select column c1 and c2 from table INSERT database ALTER TABLE table_name It is used to add columns to VALUES (value_1, 'value_2', to a table It is used to specify that table t, where c1=test t1 and perform a right join between ALTER table ADD column_name datatype; a table in a database value_3); SELECT SELECT DISTINCT column_name the statement is a query t1 and t2 SELECT column_name(s) SELECT column_name(s) It is a operator used with SELECT c1, c2 IS NULL/ IS DISTINCT FROM table_name; which returns unique SELECT c1 FROM t FROM table_name It is an operator that is used FROM table_name the WHERE clause to check FROM t1 AND NOT NULL values in specified columns ORDER BY c1 ASC (DESC) WHERE column_1 = value_1 to combine two conditions WHERE column_name IS NULL; for the empty values FULL OUTER JOIN t2 on condition It is function used to return To select data in column c1 from It is an special operator SELECT SUM(column_name) Select column c1 and c2 from table AND column_2 = value_2; SELECT column_name(s) SUM sum of values from a table t either in ascending or used with the WHERE FROM table_name; t1 and perform a full outer join It is an keyword in SQL that FROM table_name particular column descending order SELECT column_name AS 'Alias’ LIKE clause to search for a between t1 and t2 AS is used to rename a column WHERE column_name LIKE UPDATE table_name FROM table_name; specific pattern in a SELECT c1, c2 or table using an alias name pattern; SET some_column = some_value It is used to edit rows in a SELECT c1 FROM t column FROM t1 SELECT column_name(s) UPDATE ORDER BY c1LIMIT n OFFSET SELECT column_name(s) It is a clause to specify the WHERE some_column = table CROSS JOIN t2 FROM table_name It is an operator used to offset LIMIT FROM table_name maximum number of rows some_value; Select column c1 and c2 from table BETWEEN WHERE column_name filter the result within a To skip the offset of rows and LIMIT number; the result set must have SELECT column_name(s) It is a clause used to filter t1 and produce a Cartesian product return the next n rows BETWEEN value_1 AND certain range It is a function that takes FROM table_name the result set to include of rows in a table value_2; WHERE SELECT c1, aggregate(c2) SELECT c1, c2 SELECT MAX(column_name) number of columns as an WHERE column_name operator the rows which where the SELECT column_name, MAX FROM t FROM t1, t2 FROM table_name; argument and return the value; condition is TRUE CASE WHEN condition THEN WITH temporary_name AS ( GROUP BY c1 Select column c1 and c2 from table largest value among them 'Result_1' WHEN condition It is a statement used to To group rows using an aggregate t1 and produce a Cartesian product It is a function that takes SELECT * CASE THEN 'Result_2' create different outputs It is used to store the result function of rows in a table number of columns as an FROM table_name) SELECT MIN(column_name) of a particular query in a SELECT c1, aggregate(c2) SELECT c1, c2 ELSE 'Result_3’ inside a SELECT statement MIN argument and return the WITH SELECT * FROM table_name; temporary table using an FROM t FROM t1 A END smallest value among FROM temporary_name alias GROUP BY c1HAVING condition INNER JOIN t2 B on condition FROM table_name; them WHERE column_name operator Group rows using an aggregate Select column c1 and c2 from table It is a function that takes the It is an operator that is SELECT column_name value; function and filter these groups t1 and join it to itself using INNER name of a column as used to filter the result set SELECT COUNT(column_name) FROM table_name using ‘HAVING’ clause JOIN clause COUNT argument and counts the OR to contain only the rows DELETE FROM table_name FROM table_name; WHERE column_name = value_1 It is used to remove the number of rows when the where either condition is DELETE WHERE some_column = column is not NULL OR column_name = value_2; rows from a table TRUE some_value; CREATE TABLE table_name ( It is a clause used to sort It is used to create a new SELECT column_name column_1 datatype, the result set by a Create table in a database and FROM table_name It is used to aggregate a column_2 datatype, ORDER BY particular column either SELECT AVG(column_name) TABLE specify the name of the ORDER BY column_name ASC | AVG numeric column and column_3 datatype numerically or FROM table_name; return its average FURTHERMORE: table and columns inside it DESC; ); alphabetically SQL Developer, SQL DBA Training Masters Program
Data Science from Scratch: The #1 Data Science Guide for Everything A Data Scientist Needs to Know: Python, Linear Algebra, Statistics, Coding, Applications, Neural Networks, and Decision Trees