SQL commands allow users to query and manipulate data. The main commands are SELECT, INSERT, UPDATE, DELETE, and ALTER. SELECT is used to retrieve data from one or more tables. INSERT adds new rows to a table. JOIN combines rows from two or more tables based on a related column between them.
SQL commands allow users to query and manipulate data. The main commands are SELECT, INSERT, UPDATE, DELETE, and ALTER. SELECT is used to retrieve data from one or more tables. INSERT adds new rows to a table. JOIN combines rows from two or more tables based on a related column between them.
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 SELECT c1 FROM t FROM t1 Revision sheet for aggregate functions in FROM table_1 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 = The commands in SQL are called Queries and they are of two types: TRUE from table t t1 and perform an inner join SELECT column_name, COUNT(*) It is used in SQL because table_2.column_name; Data Definition Query: The statements which defines the between t1 and t2 FROM table_name the WHERE keyword It is a function that takes structure of a database, create tables, specify their keys, HAVING SELECT c1, c2 GROUP BY column_name cannot be used in the column name and a SELECT * FROM t FROM t1 indexes and so on HAVING COUNT(*) > value; aggregating functions SELECT ROUND(column_name, integer as an argument, LEFT JOIN t2 on condition Data manipulation queries: These are the queries which ROUND integer) and rounds the values in a To select all rows and columns Select column c1 and c2 from table can be edited. SELECT column_name(s) FROM table_name; column to the number of from table t t1 and perform a left join between t1 INNER JOIN FROM table_1 It is used to combine rows decimal places specified by and t2 E.g.: Select, update and insert operation JOIN table_2 from different tables if the an integer ON table_1.column_name = Join condition goes TRUE SELECT c1, c2 table_2.column_name; It is a statement that is SELECT c1 FROM t FROM t1 SELECT column_name SELECT used to fetch data from a WHERE c1 = ‘test’ RIGHT JOIN t2 on condition INSERT INTO table_name FROM table_name; Command Syntax Description database To select data in column c1 from Select column c1 and c2 from table INSERT (column_1, column_2, column_3) It is used to add new rows table t, where c1=test t1 and perform a right join between 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 ALTER table ADD column_name datatype; a table in a database t1 and t2 value_3); SELECT SELECT DISTINCT column_name the statement is a query 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 AND column_2 = value_2; It is an special operator SELECT SUM(column_name) Select column c1 and c2 from table 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; SELECT c1 FROM t column SET some_column = some_value It is used to edit rows in a FROM t1 SELECT column_name(s) UPDATE ORDER BY c1LIMIT n OFFSET WHERE some_column = table CROSS JOIN t2 FROM table_name It is an operator used to SELECT column_name(s) It is a clause to specify the offset some_value; Select column c1 and c2 from table BETWEEN WHERE column_name filter the result within a LIMIT FROM table_name maximum number of rows To skip the offset of rows and t1 and produce a Cartesian product LIMIT number; the result set must have SELECT column_name(s) It is a clause used to filter return the next n rows BETWEEN value_1 AND certain range of rows in a table It is a function that takes FROM table_name the result set to include value_2; WHERE SELECT MAX(column_name) number of columns as an WHERE column_name operator the rows which where the SELECT c1, aggregate(c2) SELECT c1, c2 SELECT column_name, MAX FROM t FROM t1, t2 FROM table_name; argument and return the value; condition is TRUE CASE WHEN condition THEN It is a statement used to GROUP BY c1 Select column c1 and c2 from table largest value among them WITH temporary_name AS ( CASE 'Result_1' WHEN condition create different outputs To group rows using an aggregate t1 and produce a Cartesian product It is a function that takes SELECT * function of rows in a table THEN 'Result_2' inside a SELECT statement It is used to store the result number of columns as an FROM table_name) ELSE 'Result_3’ SELECT MIN(column_name) of a particular query in a SELECT c1, aggregate(c2) SELECT c1, c2 MIN argument and return the WITH SELECT * FROM t FROM t1 A END FROM table_name; temporary table using an smallest value among FROM temporary_name GROUP BY c1HAVING condition INNER JOIN t2 B on condition FROM table_name; alias 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 value; SELECT column_name 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; TRUE rows from a table 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 It is used to aggregate a Create table in a database and FROM table_name All the very Best for your exam!!! 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; table and columns inside it DESC; return its average ); alphabetically