Skip to main content

SQL 5 Minutes Read

SQL CHEAT SHEET (5 Minutes Read of Structured Query Language (SQL))




SQL (Structured Query Language) is a standardised programming language used to manage relational databases and execute various operations on related data. SQL, which was developed in the 1970s, is now widely used not only by database administrators but also by developers building data integration scripts and data analysts wanting to set up and perform analytical queries. 

SQL is used to modify database table and index structures, add, update, and delete rows of data, and retrieve subsets of information from inside a database for transaction processing and analytics applications. Queries and other SQL operations take the form of statements, which are regularly used instructions. Select, add, insert, update, delete, create, change, and truncate are all SQL statements.

In this blog, we will learn how to perform basic operations in SQL. Get function for inserting data, update data, deleting data, grouping data, order data, etc. If you have started using SQL this is the best reference guide.

SQL Facts 

SQL stands for Structured Query Language. 

SQL is pronounced "sequel". 

SQL is a declarative language. 

SQL is used to access & manipulate data in databases. 

Top SQL DBs are MS SQL Server, Oracle, DB2, and MYSQL. 

Database Definitions 

RDBMS (Relational Database Management System) - Software that stores and manipulates data arranged in relational database tables. 

Table - A set of data arranged in columns and rows. The columns represent characteristics of stored data and the rows represent actual data entries. 

How to select data from a table 

SELECT <Column List> 

FROM <Table Name> 

WHERE <Search Condition> 

Example: SELECT FirstName, LastName, OrderDate 

FROM Orders WHERE OrderDate > '15/12/2020

SQL Commands Categories 

Data Query Language (DQL) 
  • SELECT - Retrieve data from table(s) 

Data Manipulation Language (DML) 
  • INSERT - Insert data into db table 
  • UPDATE - Update data in db table 
  • DELETE - Delete data from table 
Data Definition Language (DDL) 
  • CREATE - Create db object (table, view, etc.) 
  • ALTER - Modify db object (table, view, etc.) 
  • DROP - Delete db object (table, view, etc.) 

Data Control Language (DCL) 
  • GRANT - Assign privilege 
  • REVOKE - remove privilege 

How to insert data in a table 
INSERT INTO <Table Name> 
(<Column List>) VALUES (<Values>)
 
Example: 
INSERT INTO Orders (FirstName, LastName, OrderDate) VALUES ('VXYZ', 'ABCDE', '15/12/2020'

How to update data in a table 
UPDATE <Table Name> 
SET <Column1>= <Value1>, <Column2> = <Value2>, 
WHERE <Search Condition> 

Example: 
UPDATE Orders 
SET FirstName = 'VXYZ', LastName 'Who' WHERE LastName='Wo' 

How to group data and use aggregates 
SELECT <Column List>, <Aggregate Function>(<Column Name>) 
FROM <Table Name> 
WHERE <Search Condition> 
GROUP BY <Column List> 

Example: 
SELECT LastName, SUM(OrderValue) 
FROM Orders 
WHERE OrderDate > '15/12/2020' 
GROUP BY LastName 

How to select data from more than one table 
SELECT <Column List> 
FROM <Table1> XYZ <Table2> 
ON <Table1>.<Column1>=<Table2>.<Column1> 

Example: 
SELECT Orders.LastName, Countries.CountryName 
FROM Orders JOIN Countries ON 
Orders.CountrylID = Countries.lID

How to delete data from a table 
DELETE FROM <Table Name> 
WHERE <Search Condition> 

Example: 
DELETE FROM Orders 
WHERE OrderDate < '15/12/2020' 

How to order data 
SELECT <Column List> 
FROM <Table Name>
WHERE <Search Condition>
ORDER BY <Column List>

Example: 
SELECT FirstName, 
LastName, OrderDate 
FROM Orders  
WHERE OrderDate > '15/12/2020'  
ORDER BY OrderDate 

Using UNION 

SELECT <Column List> FROM <Table1> 
UNION 
SELECT <Column List> FROM <Table2> 

Example: 
SELECT FirstName, LastName FROM Orders2020 
UNION 
SELECT FirstName, LastName FROM Orders2021 

CREATE TABLE 

CREATE TABLE <Table Name> 

( Column1 DataType,
Column2 DataType,
Column3 DataType,
...   )

CREATE TABLE Orders    
( FirstName CHAR(100), 
LastName CHAR(100), 
OrderDate DATE, 
OrderValue Currency ) 

Any comments or suggestions are welcome.

Thanks for reading this blog. 


 

Comments

Popular posts from this blog

UPSC ISS 2020 Toppers Marksheet

Union Public Service Commission  Indian Statistical Service 2020 List of Candidates whose mark sheet is attached in this Blog. 1. NIPUN JAIN  2 JAGRTI GARG  3 LAXMI NARAYAN VERMA  4 CHHAJED HARSHADA NANDALAL   5 PREETAM SEN  6 NAUSHEEN MUSHARRAF  7 SUJIT PADHAN  8 ANCHAL JAIN  9 KIRTI ARORA  10 SUTAPA GHOSH 11 HARSHVARDHAN SINGH GARHWAL 12 KALPNA 13 BHAVNA MISHRA 14 DIVYANSHU MISHRA 15 SHIKHA RAI 16 NAVDEEP KAUR  27 ABHISHEK GAURAV  You can send your mark sheet on our Email: statistics.for.help@gmail.com UPSC ISS 2020 AIR 01 "NIPUN JAIN" UPSC ISS 2020 AIR 02  "JAGRTI GARG"  UPSC ISS 2020 AIR 03  "LAXMI NARAYAN VERMA" UPSC ISS 2020 AIR 04  "CHHAJED HARSHADA NANDALAL"  UPSC ISS 2020 AIR 05  "PREETAM SEN" UPSC ISS 2020 AIR 06  "NAUSHEEN MUSHARRAF" UPSC ISS 2020 AIR 07  "SUJIT PADHAN" UPSC ISS 2020 AIR 08  "ANCHAL JAIN" UPSC ISS 2020 AIR 09  "KIRTI ARORA" UPSC IS...
3. TOP 10 Statistics, Python, and SQL c oncepts for Job Interview By "Statistics For You"   TOP 10 Statistics Concepts for Job Interview 1. Sampling and Sample Size Estimation 2. Experiments (A/B tests) 3. Descriptive Statistics (Mean/Median/SD) 4. p-value and Significance Level 5. Probability Distributions 6. Z-test and t-test 7. Conditional Probability and Bayes’ Theorem 8. Correlation 9. Linear Regression 10. Logistic Regression TOP 10 Python Concepts for Job Interview 1. Reading data from file/table 2. Writing data to file/table 3. Data Types 4. Function 5. Data Processing (Numpy/Pandas) 6. Data Visualisation (Matplotlib/seaborn) 7. Machine Learning (klearn) 8. Deep Learning (Tensorflow/Keras/PyTorch) 9. Distributed Processing (PySpark) 10. Functional and Object-Oriented Programming TOP 10 SQL Concepts for Job Interview 1. Aggregate Functions (sum/avg/max/min) 2. Group By and Order By 3. JOINs (Inner/Left/Right/Self) 4. Union and Union All 5. Date and Time processing 6. S...

UPSC Previous year paper for AD Census Operations (Technical) & Statistical Officer (Planning/Statistics)

UPSC Previous year paper for AD Census Operations (Technical) & Statistical Officer (Planning/Statistics) Syllabus of the Test:  (1) Statistical Methods (2) Sampling Techniques/Survey Methodology (3) Demography and Vital Statistics (4) Fundamentals of Applied Multivariate Analysis (5) Official Statistics (6) Basic knowledge in Computer Applications UPSC 2017 Paper   For PDF file, click on the below link: https://drive.google.com/file/d/14oDfPYGI9bA2g0m-0OmfexHS8LOgaf3j/view?usp=sharing (There are 25 slides) For PDF file, click on the below link: https://drive.google.com/file/d/14oDfPYGI9bA2g0m-0OmfexHS8LOgaf3j/view?usp=sharing Any comments or suggestions are welcome. Subscribe our Youtube Channel----->  Thanks for reading this blog.