SQL Beginner Friendly Cheatsheet

1. Retrieving/Selecting Data –

The SELECT statement is used to select data from a database.

SELECT column_name FROM table_name;

for eg –

SELECT StudentName FROM Student;

2. Selecting All Records/Columns of Data …


This content originally appeared on DEV Community and was authored by Durgesh Mahajan

1. Retrieving/Selecting Data -

The SELECT statement is used to select data from a database.

SELECT column_name FROM table_name;

for eg -

SELECT StudentName FROM Student;

2. Selecting All Records/Columns of Data -

The Asterisk(*) is used to select all records.

SELECT * FROM table_name;

for eg -

SELECT * FROM Student;

3. Selecting Distinct Data -

The SELECT DISTINCT statement is used to return only distinct (different) values.

SELECT DISTINCT column_name FROM table_name;

for eg -

SELECT DISTINCT StudentName FROM Student;

4. Filtering the Records -

The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.

SELECT column_name FROM table_name WHERE condition;

for eg -

SELECT * FROM Student WHERE Marks>=450;

5. Filtering the Records by two or more conditions -

The WHERE clause can be combined with AND, OR, and NOT operators.
The AND and OR operators are used to filter records based on more than one condition.
The NOT operator displays a record if the condition(s) is NOT TRUE.

SELECT column_name FROM table_name WHERE condition1 AND condition2 OR condition3;
SELECT column_name FROM table_name WHERE NOT condition;

for eg -

SELECT * FROM Student WHERE Marks>=450 AND Div="A";
SELECT * FROM Student WHERE NOT Marks=500;

6. Sorting the Data of Records -

The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

SELECT column_name FROM table_name ORDER BY column_name;

for eg -

SELECT * FROM Student ORDER BY Marks DESC;

7. Inserting Data -

The INSERT INTO statement is used to insert new records in a table.

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table.

for eg -

INSERT INTO Student (StudentName, Class, Div, Marks)
VALUES ("Durgesh", "Second Year", "B", 450);

8. Updating Data -

The UPDATE statement is used to modify the existing records in a table.
If you omit the WHERE clause, ALL records will be updated!

UPDATE table_name SET column=value WHERE condition;

for eg -

UPDATE Student SET Marks=440 WHERE StudentName="Durgesh";

Follow for more :-)

Linkedin
Github
Instagram


This content originally appeared on DEV Community and was authored by Durgesh Mahajan


Print Share Comment Cite Upload Translate Updates
APA

Durgesh Mahajan | Sciencx (2022-01-23T14:18:29+00:00) SQL Beginner Friendly Cheatsheet. Retrieved from https://www.scien.cx/2022/01/23/sql-beginner-friendly-cheatsheet/

MLA
" » SQL Beginner Friendly Cheatsheet." Durgesh Mahajan | Sciencx - Sunday January 23, 2022, https://www.scien.cx/2022/01/23/sql-beginner-friendly-cheatsheet/
HARVARD
Durgesh Mahajan | Sciencx Sunday January 23, 2022 » SQL Beginner Friendly Cheatsheet., viewed ,<https://www.scien.cx/2022/01/23/sql-beginner-friendly-cheatsheet/>
VANCOUVER
Durgesh Mahajan | Sciencx - » SQL Beginner Friendly Cheatsheet. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/23/sql-beginner-friendly-cheatsheet/
CHICAGO
" » SQL Beginner Friendly Cheatsheet." Durgesh Mahajan | Sciencx - Accessed . https://www.scien.cx/2022/01/23/sql-beginner-friendly-cheatsheet/
IEEE
" » SQL Beginner Friendly Cheatsheet." Durgesh Mahajan | Sciencx [Online]. Available: https://www.scien.cx/2022/01/23/sql-beginner-friendly-cheatsheet/. [Accessed: ]
rf:citation
» SQL Beginner Friendly Cheatsheet | Durgesh Mahajan | Sciencx | https://www.scien.cx/2022/01/23/sql-beginner-friendly-cheatsheet/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.