Clauses
Clauses How to Use It Functionality
CREATE
CREATE TABLE table_name ... Creates a new table
TABLE
INSERT INSERT INTO table_name ... Used to insert new data in the table
SELECT SELECT col1, col2 .. Retrieves the selected columns
SELECT SELECT * FROM ... Retrieves all the columns from a table
FROM clause specifies the table(s) in
FROM FROM table_name
data columns are located
WHERE WHERE col > 5 Retrieves only specific rows based on t
UPDATE, UPDATE table_name SET column1 = Updates the value of a column of a
SET value1; specific rows using WHERE clause)
DELETE DELETE FROM table_name Deletes all the rows from the table
DROP DROP TABLE table_name Deletes the table from the database
ALTER ALTER TABLE table_name ... Used to add, delete or modify columns
Sorts the table based on the column(s
ORDER BY ORDER BY col1 ASC/DESC..
descending orders
DISTINCT SELECT DISTINCT col, ... Gets the unique values of given colum
Limits the number of rows in the outp
LIMIT LIMIT 10
number
Specifies the position (from nth row) f
OFFSET OFFSET 5
of the results are to be retrieved
GROUP BY GROUP BY col ... Groups the rows that have same values
Filters the resultant rows after the app
HAVING HAVING col > 20
clause
CASE WHEN condition1 THEN value1 Returns a corresponding value when
CASE
WHEN .. ELSE .. END met
Operators
Operators How to Use It Functionality
Filters the rows where the given column is not equal
<> WHERE col <> 5
comparison operators (=,>,<,>=,<=) are also used.
WHERE col LIKE
LIKE Retrieves the rows where the given column has 'apple
'%Apple%'
WHERE col1 > 5 AND
AND Retrieves the rows that satisfy all the given conditions
col2 < 3
WHERE col1 > 5 OR col2
OR Retrieves the rows that satisfy at least one condition
<3
NOT WHERE NOT col = 'apple' Retrieves the rows if the condition(s) is NOT TRUE
WHERE col IN ('Apple',
IN Retrieves the rows if the column value is present in th
'Microsoft')
WHERE col BETWEEN 3 Retrieves the rows if the column value is present bet
BETWEEN
AND 5 the given values
Functions
Functions How to Use It Functionality
SELECT COUNT(col)
COUNT Counts the number of values in the given column
...
SUM SELECT SUM(col) ... Adds all the values of given column
MIN SELECT MIN(col) ... Gets the minimum value of given column
MAX SELECT MAX(col) ... Gets the maximum value of given column
AVG SELECT AVG(col) ... Gets the average of the values present in the given column
Extracts the year from the column value in string format. Sim
strftime() strftime("%Y", col) ...
month, day, week of the day and many.
CAST(col AS
CAST() Converts the value to the given datatype
datatype) ...
FLOOR() FLOOR(col) Rounds a number to the nearest integer below its current v
Functions How to Use It Functionality
CEIL() CEIL (col) Rounds a number to the nearest integer above its current v
ROUND() ROUND(col) Rounds a number to a specified number of decimal places
UPPER() UPPER(col) Converts a string to upper case
LOWER() Lower(col) Converts a string to lower case