0% found this document useful (0 votes)
40 views5 pages

List of SQL Commands - Codecademy

The document is a list of commonly used SQL commands along with a brief description of each one. It begins with background information on SQL and relational databases. Then it lists 24 different SQL commands (ALTER TABLE, AND, AS, etc.), each followed by a simple example of its usage and a short explanation of its purpose. The commands are listed alphabetically to serve as an easy reference for SQL functions.

Uploaded by

Harish Bisht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views5 pages

List of SQL Commands - Codecademy

The document is a list of commonly used SQL commands along with a brief description of each one. It begins with background information on SQL and relational databases. Then it lists 24 different SQL commands (ALTER TABLE, AND, AS, etc.), each followed by a simple example of its usage and a short explanation of its purpose. The commands are listed alphabetically to serve as an easy reference for SQL functions.

Uploaded by

Harish Bisht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

25/07/2016

ListofSQLcommands|Codecademy

ListofSQLcommands|Codecademy

Background
SQL,'StructuredQueryLanguage',isaprogramminglanguagedesignedtomanagedatastoredin
relationaldatabases.SQLoperatesthroughsimple,declarativestatements.Thiskeepsdataaccurateand
secure,andhelpsmaintaintheintegrityofdatabases,regardlessofsize.
Here'sanappendixofcommonlyusedcommands.

Commands
ALTERTABLE
ALTERTABLEtable_nameADDcolumndatatype;
ALTERTABLEletsyouaddcolumnstoatableinadatabase.

AND
SELECTcolumn_name(s)
FROMtable_name
WHEREcolumn_1=value_1
ANDcolumn_2=value_2;
ANDisanoperatorthatcombinestwoconditions.Bothconditionsmustbetruefortherowtobeincludedin
theresultset.

AS
SELECTcolumn_nameAS'Alias'
FROMtable_name;
ASisakeywordinSQLthatallowsyoutorenameacolumnortableusinganalias.

AVG
SELECTAVG(column_name)
FROMtable_name;
AVG()isanaggregatefunctionthatreturnstheaveragevalueforanumericcolumn.

https://www.codecademy.com/articles/sqlcommands?r=master

1/5

25/07/2016

ListofSQLcommands|Codecademy

BETWEEN
SELECTcolumn_name(s)
FROMtable_name
WHEREcolumn_nameBETWEENvalue_1ANDvalue_2;
TheBETWEENoperatorisusedtofiltertheresultsetwithinacertainrange.Thevaluescanbenumbers,text
ordates.

COUNT
SELECTCOUNT(column_name)
FROMtable_name;
COUNT()isafunctionthattakesthenameofacolumnasanargumentandcountsthenumberofrows
wherethecolumnisnotNULL.

CREATETABLE
CREATETABLEtable_name(column_1datatype,column_2datatype,column_3datatype);
CREATETABLEcreatesanewtableinthedatabase.Itallowsyoutospecifythenameofthetableandthe
nameofeachcolumninthetable.

DELETE
DELETEFROMtable_nameWHEREsome_column=some_value;
DELETEstatementsareusedtoremoverowsfromatable.

GROUPBY
SELECTCOUNT(*)
FROMtable_name
GROUPBYcolumn_name;
GROUPBYisaclauseinSQLthatisonlyusedwithaggregatefunctions.Itisusedincollaborationwiththe
SELECTstatementtoarrangeidenticaldataintogroups.

INNERJOIN
SELECTcolumn_name(s)FROMtable_1
JOINtable_2
ONtable_1.column_name=table_2.column_name;
Aninnerjoinwillcombinerowsfromdifferenttablesifthejoinconditionistrue.
https://www.codecademy.com/articles/sqlcommands?r=master

2/5

25/07/2016

ListofSQLcommands|Codecademy

INSERT
INSERTINTOtable_name(column_1,column_2,column_3)VALUES(value_1,'value_2',
value_3);
INSERTstatementsareusedtoaddanewrowtoatable.

LIKE
SELECTcolumn_name(s)
FROMtable_name
WHEREcolumn_nameLIKEpattern;
LIKEisaspecialoperatorusedwiththeWHEREclausetosearchforaspecificpatterninacolumn.

LIMIT
SELECTcolumn_name(s)
FROMtable_name
LIMITnumber;
LIMITisaclausethatletsyouspecifythemaximumnumberofrowstheresultsetwillhave.

MAX
SELECTMAX(column_name)
FROMtable_name;
MAX()isafunctionthattakesthenameofacolumnasanargumentandreturnsthelargestvalueinthat
column.

MIN
SELECTMIN(column_name)
FROMtable_name;
MIN()isafunctionthattakesthenameofacolumnasanargumentandreturnsthesmallestvalueinthat
column.

OR
SELECTcolumn_name
FROMtable_name
WHEREcolumn_name=value_1
ORcolumn_name=value_2;

https://www.codecademy.com/articles/sqlcommands?r=master

3/5

25/07/2016

ListofSQLcommands|Codecademy

ORisanoperatorthatfilterstheresultsettoonlyincluderowswhereeitherconditionistrue.

ORDERBY
SELECTcolumn_name
FROMtable_name
ORDERBYcolumn_nameASC|DESC;
ORDERBYisaclausethatindicatesyouwanttosorttheresultsetbyaparticularcolumneither
alphabeticallyornumerically.

OUTERJOIN
SELECTcolumn_name(s)FROMtable_1
LEFTJOINtable_2
ONtable_1.column_name=table_2.column_name;
Anouterjoinwillcombinerowsfromdifferenttablesevenifthethejoinconditionisnotmet.Everyrowinthe
lefttableisreturnedintheresultset,andifthejoinconditionisnotmet,thenNULLvaluesareusedtofillin
thecolumnsfromtherighttable.

ROUND
SELECTROUND(column_name,integer)
FROMtable_name;
ROUND()isafunctionthattakesacolumnnameandanintegerasanargument.Itroundsthevaluesinthe
columntothenumberofdecimalplacesspecifiedbytheinteger.

SELECT
SELECTcolumn_nameFROMtable_name;
SELECTstatementsareusedtofetchdatafromadatabase.EveryquerywillbeginwithSELECT.

SELECTDISTINCT
SELECTDISTINCTcolumn_nameFROMtable_name;
SELECTDISTINCTspecifiesthatthestatementisgoingtobeaquerythatreturnsuniquevaluesinthe
specifiedcolumn(s).

SUM
SELECTSUM(column_name)
FROMtable_name;

https://www.codecademy.com/articles/sqlcommands?r=master

4/5

25/07/2016

ListofSQLcommands|Codecademy

SUM()isafunctionthattakesthenameofacolumnasanargumentandreturnsthesumofallthevaluesin
thatcolumn.

UPDATE
UPDATEtable_name
SETsome_column=some_value
WHEREsome_column=some_value;
UPDATEstatmentsallowyoutoeditrowsinatable.

WHERE
SELECTcolumn_name(s)
FROMtable_name
WHEREcolumn_nameoperatorvalue;
WHEREisaclausethatindicatesyouwanttofiltertheresultsettoincludeonlyrowswherethefollowing
conditionistrue.

Teachingtheworldhowtocode.
Company

https://www.codecademy.com/articles/sqlcommands?r=master

5/5

You might also like