MySQL Cheatsheet
Database
itis defined as a collection of interrelated data stored together to serve multiple applications
MySQL Elements
MySQL has certain elements that play an important role in querying a database,
Literals
Literals refer to a fixed data value
a
Pace eee et cto
Data Types
Data types are means to identity the type of data
coer
EG eR Ty
Doe
SHALLINT
Porch esc)
CnC eta en ee ec nee acer
cent eet eno ears
Peer
eos eae}
Phaedra ec Sete Soret eae Te
ee cree se MCT)
coeur
CC eee
Se eRe eee e ESTs
eo
NULL Values
Ifa columa has no value, then its said to be NU!
CommentsWorks Where You Write
iy offs sugges e
Grammarly
ess a sangue-nine commend
Pe eee ees Cetera
MySQL Simple Calculations
You can perform simple calculations in MySQl, just by using the Select command, there's no need to select
‘any particular database to perform these commands.
Addition
Ik will age two numbers
select 5+8;
Subtraction
‘twill subtract the second number from first
Multiplication
Ie will give the product of supplied numbers
Division
Ie will divide the number
Stree
Accessing Database
‘These commands allow ane to check all the databases and tables
‘Show command
It will how all the databases in the system
It will how athe tables in a selected database
coments
Use command
It will start using the specified database Le. now you can create tables in the selected database
ccdThis query is usea to create a table in the selected database:
Pee See seers
tee ee
Poteet e
fr roescsy
Insert command
It will add data into the solectes table
PCRS SUR em Ccotisteiss)
Sener ete one
Inserting NULL values
This query will add NULL value in the col3 ofthe s
eee sees
Cotman
Inserting Dates
twill add the following data into the selected column of the table
eee SCR emcee
Select Command
A select query is used to fetch the data from the database
Selecting All Data
Iwill retrieve all the data ofthe se
sd table
comes
Selecting Particular Rows
Ie will retrieve all the data ofthe row that will satisfy the condition
eee eee
Perr Comet
Selecting Particular Columns
Ie will retrieve data of selectee columns that will satisly the condition
Patera er ecrecist
Pere ee eee ees
DISTINCT Keyword
Iwill rotriove only distinct data Lo. duplicate dats rows will get oliminatedeee
Column Aliases
It is used to give a temporary name ta a table ora column ina table for the purpose of a particular query
Sreraecestrey
ees enrey
Condition Based on a Range
twill only retrieve data of those columns whose values will fall between valuel and value? (both inclusive)
aerate
een
mere
Between s
Condition Based on a List
See eee
Sete RC eeeenaTe!
otras
poecstt
casera
elect , ¢col2>
een
Peaster any a
Searching NULL
Ie returns data that contains @ NUL value in them
aero Seo.
eee ee Stee
SQL Constraints
SQL constraints are the rules or checks enforced on the dats columns of a table
NOT NULL
Iwill create a table with NOT NULL constraint to its first column,DEFAULT
DEFAULT constraint provides a default value toa column
canis aesno
pee
UNIQUE
UNIQUE constraint ensures that all values in the column are different
Cree oes
CHECK
CHECK constraint ensures that ll values in a colurnn satisfy certain conditions
Pee Steer
tren Me cem correc n
ore ees oe
eres
Primary Key
Primary key is Used to uniquely identify each row ina table
Foreign Key
Crea
Cee Cru oan
eee aa
i
Da Crao
Viewing Table Structure
Desc or Describe command
Itallows you to see the table steuetureupuate Guu nenU
‘twill update the values of selected columns
feneerestnres
SET = , =
Peete
Deleting Data
Delete Command
Ie will delat the entira row that will satisfy the condition
Cees Ont
Peer tet
Ordering Records
Order by clause is used to sort the data in ascending or descending order of spe
order by clause
Iwill return records in the ascending arder of the specified column name's data
Soe Cae ae me
Ik will return records in the descending order ofthe specified column name's data
select * from order by DE:
Ordering data on multiple columns
It will return records in the ascending order of column and descending order of column?
eee eS ame a eC aR eared
Grouping Result
Itis used to arrange identical data into groups so that aggregate functions can work on them,
Group by clause
Irallows you to group two or more colurmns and then you can perform aggregate fu
ion an them
eee ee Oe re On ee arn mero
Having clause
Having clause is used to put conditions on groups
ct avg(), sum() from group by having ) “Alias Name” fron s
SUM Function
reren
rns the sum of values in given column
Sear Cres eee eer eee
MySQL Joins
Join clouseis use to combine or merge ows fram two or more tables based ona elated attribute
INNER JOIN
It returns all rows from multiple tables where the jain concition is satisfied, It is the most common type of
jin
Sete Res Ce en mt ste teeters Cement eeotcn
LEFT OUTER JOIN
It returns all rows from the left-hand table specified inthe ON condition and only those rows from the other
table where the join condition is fulfilled
See eee aCe kt neste ens ot
RIGHT OUTER JOIN
It returns all rows from the RIGHT-hand table specified in the ON condition and only these rows from the
‘other table where the join condition is satisfied
Soe Ree not ees tet eect
FULLJOIN
Itcombines the results of bot
loft and right outer joins
Soe ee Cee eS eee e eesti
‘SELF JOIN
In this join, table is joined with itself
ate eee
Download this CheatsheetComments (19)
rohitmstas 293.61)
‘ay tefl and awesome
tejasayarekarS_gm 20212009
‘Thankyou so much Har bh
shirazshayan.gm 2023034
Thanks bro, Very Useful Alo your wabste/og is wry simple and easy to aces
teh3 1385 2025.02
Wow Amazing hpsi/now-earn-ecountng blogspot.com
adityakumar09899.gm 20202930
‘Thanks bro this chest sheet helped me a ot
Ishangangwani3841 2030126
‘thankyou sr ths will bea great help in my school exams
wevivekumar_gm 20:2.9108
brayou are awesome love rom core of heart uri khan si physics
walsh plage make ful ttorilon data science please
sghakshatt3_gm 20.0.0
Thank you Hany Bhsdmmamidwar_mi
-MyS@L pe vdeo banao bhava
8 CodeWithHarry —copyiaht © 2072 codewibiinycon f¥@QO