//

SQL Queries

SELECT

Fetch all records of a table

SELECT * from <table_name>

Fetch data from specific columns of all records of a table

SELECT <column1>, <column2> FROM <table_name>

Fetch specific records of a table using “WHERE”

SELECT * FROM &lt;table_name> WHERE &lt;column_name> = &lt;value>

Fetch specific records on the condition of a single column using “IN”

SELECT * FROM <table_name> WHERE <column_name> IN (<value1>, <value2>)

Group specific records on the basis of the column using “GROUP BY”

SELECT count(<column_name>), <column_name> FROM <table_name> GROUP BY <column_name>;

Order the fetched records using “ORDER BY”

SELECT * FROM <table_name> ORDER BY <column>;

INSERT

Insert data into DB

INSERT INTO <table_name>  ( <column1>, <column2>) VALUES (<value1>,<value2>, <value3> )

UPDATE

Update a particular column for all records of Table

UPDATE <table_name> SET <column1> = <value1>, <column2> = <value2>

Update a particular column for specific records of Table using “WHERE”

UPDATE <table_name> SET <column1> = <value1>, <column2> = <value2> WHERE <column_name> = <value>

Update particular column for specific records of Table using “IN”

UPDATE <table_name> SET <column1> = <value1>, <column2> = <value2> WHERE <column> IN ( <value1>, <value2> )

DELETE

Delete all records of Table

DELETE FROM <table_name>;

Update a particular column for specific records of Table using “WHERE”

DELETE FROM <table_name> WHERE <column_name> = <value>

Update particular column for specific records of Table using “IN”

DELETE FROM <table_name> WHERE <column_name> IN (<value1>, <value2>)

Leave a Reply

Your email address will not be published. Required fields are marked *