Points to Note:
- SQL keywords are not case sensitive ie., select and SELECT are the same.
- A semicolon is mandatory at the end of each SQL statement.
Important SQL Commands:
COMMAND |
DESCRIPTION |
SELECT |
extracts data from a database |
UPDATE |
updates data in a database |
DELETE |
deletes data from a database |
INSERT INTO |
inserts new data into a database |
CREATE DATABASE |
creates a new database |
ALTER DATABASE |
modifies a database |
CREATE TABLE |
creates a new table |
ALTER TABLE |
modifies a table |
DROP TABLE |
deletes a table |
CREATE INDEX |
creates an index |
DROP INDEX |
deletes an index |
QUERIES
QUERY |
DESCRIPTION |
OUTPUT |
|
Displays the mentioned fields of all the records in the table |
|
|
Displays all the fields of all the records in the table |
|
|
Displays the unique values in the mentioned fields of all the records in the table |
|
|
Filters the records based on the condition. Only those records that satisfy the condition mentioned in the WHERE clause is displayed |
|
|
Displays all the records in which all the conditions separated by AND are TRUE. |
|
|
Displays a record if any of the conditions separated by OR is TRUE. |
|
|
Displays a record if the condition(s) is NOT TRUE. |
|
|
Displays the records arranged in ascending order of values in the mentioned column. |
|
|
Displays the records arranged in descending order of values in the mentioned column. |
|
|
Displays the records with NULL value in the mentioned column. |
|
|
Displays the records with non-NULL value in the mentioned column. |
|
|
Modifies the existing records in the table. |
Table after executing the statement:
|
|
Deletes existing records in the table. |
Table after executing the statement:
|
|
Inserts new records into the table. |
Table after executing the statement:
|
|
Returns the largest value in the mentioned column. |
|
|
Returns the smallest value in the mentioned column. |
|
|
Returns the number of rows that match the specified condition. |
|
|
Used to search for a specific pattern.
|
|
|
The ‘IN’ operator is used to specify multiple values in the where clause. It is a shorthand for multiple OR conditions.
|
|
|
Returns records that have matching values in both the tables. |
|
|
Groups rows that have the same values into summary statements. The ‘group by’ statement is often used with aggregate functions like count(), sum(), max(), min(), avg() |
|
|
The ‘having clause’ is used to filter the output of the ‘group by’ clause by a specific condition. |
|