Milestone 1 Cheat Sheet

 Clauses

ClausesHow to Use ItFunctionality
CREATE TABLECREATE TABLE table_name ...Creates a new table
INSERTINSERT INTO table_name ...Used to insert new data in the table
SELECTSELECT col1, col2 ..Retrieves the selected columns
SELECTSELECT * FROM ...Retrieves all the columns from a table
FROMFROM table_nameFROM clause specifies the table(s) in which the required data columns are located
WHEREWHERE col > 5Retrieves only specific rows based on the given conditions
UPDATE, SETUPDATE table_name SET column1 = value1;Updates the value of a column of all the rows (or only specific rows using WHERE clause)
DELETEDELETE FROM table_nameDeletes all the rows from the table
DROPDROP TABLE table_nameDeletes the table from the database
ALTERALTER TABLE table_name ...Used to add, delete or modify columns in a table
ORDER BYORDER BY col1 ASC/DESC..Sorts the table based on the column(s) in the ascending or descending orders
DISTINCTSELECT DISTINCT col, ...Gets the unique values of given column(s)
LIMITLIMIT 10Limits the number of rows in the output to the mentioned number
OFFSETOFFSET 5Specifies the position (from nth row) from where the chunk of the results are to be retrieved
GROUP BYGROUP BY col ...Groups the rows that have same values in the given columns
HAVINGHAVING col > 20Filters the resultant rows after the application of GROUP BY clause
CASECASE WHEN condition1 THEN value1 WHEN .. ELSE .. ENDReturns a corresponding value when the first condition is met

Operators

OperatorsHow to Use ItFunctionality
<>WHERE col <> 5Filters the rows where the given column is not equal to 5. Similarly, other comparison operators (=,>,<,>=,<=) are also used.
LIKEWHERE col LIKE '%Apple%'Retrieves the rows where the given column has 'apple' within the text
ANDWHERE col1 > 5 AND col2 < 3Retrieves the rows that satisfy all the given conditions
ORWHERE col1 > 5 OR col2 < 3Retrieves the rows that satisfy at least one condition
NOTWHERE NOT col = 'apple'Retrieves the rows if the condition(s) is NOT TRUE
INWHERE col IN ('Apple', 'Microsoft')Retrieves the rows if the column value is present in the given values
BETWEENWHERE col BETWEEN 3 AND 5Retrieves the rows if the column value is present between (and including) the given values

Functions

FunctionsHow to Use ItFunctionality
COUNTSELECT COUNT(col) ...Counts the number of values in the given column
SUMSELECT SUM(col) ...Adds all the values of given column
MINSELECT MIN(col) ...Gets the minimum value of given column
MAXSELECT MAX(col) ...Gets the maximum value of given column
AVGSELECT AVG(col) ...Gets the average of the values present in the given column
strftime()strftime("%Y", col) ...Extracts the year from the column value in string format. Similarly, we can extract month, day, week of the day and many.
CAST()CAST(col AS datatype) ...Converts the value to the given datatype
FLOOR()FLOOR(col)Rounds a number to the nearest integer below its current value
CEIL()CEIL (col)Rounds a number to the nearest integer above its current value
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

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form