SlideShare a Scribd company logo
1 of 125
SQL Fundamentals
Part - 1
Topics
1. Understanding Big Picture
2. Retrieving the data
a. Select
b. Distinct
c. Count
d. Where
e. Order By
f. Limit
g. Between
h. In
Which data exactly I am talking about ?
Where to store the data ?
Big Picture
Why we need SQL ?
Database Management System
● Databases are collections of information — or data — that have been
logically modeled.
● The computer programs that interact with databases are called database
management systems, or DBMSs.
SQL Standards
● IEC — The International Electrotechnical Commission;
● ISO — The International Organization for Standardization;
● ANSI —The American National Standards Institute.
Database Operations
Select Statement
● Used to retrieve Information
Syntax :
● SELECT COLUMN_NAME FROM TABLE_NAME
Query
● Run in a Backward Manner
SELECT column1 FROM table
Select Statement
1. SINGLE COLUMN
2. MULTIPLE COLUMN
1. SINGLE COLUMN
● SELECT column1 FROM table_1
2. MULTIPLE COLUMN
● SELECT column1, column2 FROM table_1
ALL COLUMNS
● Get All Columns.
SELECT * FROM table_1
DISTINCT
● To list the distinct values.
SELECT DISTINCT column FROM table.
DISTINCT
● To list the distinct values.
How many different continents are their ?
SELECT DISTINCT(column) FROM table.
COUNT
● Returns number of input rows that matches a specific condition of a query.
Note : It won’t work without parenthesis.
SELECT COUNT(column_name) FROM table_name.
COUNT
● Count -> return number of rows
● Count is useful with other commands like distinct.
HOW MANY UNIQUE NAMES ARE THERE IN THE TABLE ?
SELECT COUNT(DISTINCT column_name) FROM table_name;
WHERE
● Where statement allows us to specify condition on column for the rows.
BASIC SYNTAX :
SELECT column1, column2
FROM table_name
WHERE condition ;
Comparison Operator
Logical Operator
Order By
● Compiler returning the output in different order each time.
● Order By is used to sort the output in ascending order or descending order.
SELECT column_1, column_2
FROM table
ORDER BY column_1 ASC/DESC
LIMIT
● Limit command limit the number of rows returned for a query.
● Limit is the last command to be executed’
Select * from table_name LIMIT 2
Between
● Used to Match the values against range of values.
○ Values Between Low and High
● Between is same as
○ Value >= low AND value <= high
SELECT * FROM table_name
WHERE column_1 BETWEEN low AND high
IN
● Checks if a value is included in a list of multiple options.
SELECT color FROM table_name WHERE color IN (‘red’, ‘blue’)
Thank You
SQL Fundamentals
Part - 2
Topics
1. Aggregate Functions
2. Group By
3. Having
Aggregate Functions
● Sql provides variety of aggregate functions.
● It returns single output.
Most Common Aggregate Functions
1. AVG() Return avg value
2. COUNT() Return number of values
3. MAX() Return maximum value
4. MIN() Return minimum value
5. SUM() Return sum of all values
Aggregate Function
● Aggregate function only used with
Select Clause or having clause.
Group By
● Group By allows us to aggregate columns per some category.
Group By
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
GROUP BY category_column
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
WHERE category_col != ‘A’
GROUP BY category_column
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
WHERE category_col != ‘A’
GROUP BY category_column
ORDER BY AVG(data_col)
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
WHERE category_col != ‘A’
GROUP BY category_column
ORDER BY AVG(data_col)
LIMIT 5
Having
● Having Clause allows us to filter after an aggregation has already
taken place.
● To perform filtering on Group By.
Having
Select company, SUM(sales)
FROM finance_table
GROUP BY company
Having sum(sales) > 1000
Having
Select company, SUM(sales)
FROM finance_table
WHERE company != ‘Google’
GROUP BY company
Having sum(sales) > 1000
Thank You
SQL Fundamentals
Part - 3
Topics
1. Data Types
2. Primary Keys & Foreign Keys
3. Constraints
4. Insert, Update, Delete
5. Alter Table
6. Drop Table
7. Check Constraint
Big Picture
Why we need Data Types ?
Data Type
Data Types
Data Types
● On Creating the Database & Tables, Carefully consider which data type should
be used for the data to be stored.
● For Eg :
○ I want to store a phone number
○ Which Data type , it should be ?
Which data type should we use ?
Why Bother Numerics at all ?
Data Types
● No Arithmetic Operation
Data Types
● Take time to Plan
● Modifying Table Later will be painful
Primary Keys
● A primary key is a column or a group of columns used to identify
the row uniquely in a table.
● Primary Keys helps in Joining the table.
Primary Key
Why we need Primary Key ?
Foreign Key
● A foreign key is a field in a table that uniquely identifies a row in another table.
● A foreign key is defined in a table that references to the primary key of the
other table.
Why we need Foreign Key ?
Create Table
● To create Table.
Constraints
1. Rules enforced on data columns on table..
2. Used to prevent invalid data from being entered in the database.
3. Ensures accuracy and reliability of data.
Create Table
● To create Table.
CREATE TABLE table_name (
column1 datatype(length) column_contraint,
column2 datatype(length) column_contraint,
table_constraints
);
Create Table
CREATE TABLE table_name (
CREATE TABLE table_name (
column1 datatype(length) column_contraint,
column2 datatype(length) column_contraint,
table_constraints
);
column1 datatype(length) column_contraint,
column2 datatype(length) column_contraint,
table_constraints
);
CREATE TABLE players (
player_id SERIAL PRIMARY KEY,
age int NOT NULL
);
Serial
● It will create a sequence of the number in the increasing order.
● Used as a primary key.
Create Table
CREATE TABLE table_name (
CREATE TABLE table_name (
column1 datatype(length) column_contraint,
column2 datatype(length) column_contraint,
table_constraints
);
column1 datatype(length) column_contraint,
column2 datatype(length) column_contraint,
table_constraints
);
CREATE TABLE players (
player_id SERIAL PRIMARY KEY,
age int NOT NULL
);
Restaurant Database
1. Customer Table
2. Food Table
3. Order Table
Customer Table
CREATE TABLE customer (
customer_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
age INT NOT NULL,
email VARCHAR(50) UNIQUE NOT NULL,
created_on TIMESTAMP NOT NULL
);
Food Table
CREATE TABLE food (
food_id
name
type
created_on
);
Food Table
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Order Table
CREATE TABLE orders (
customer_id ,
food_id ,
Order_time
);
Order Table
CREATE TABLE orders (
customer_id INTEGER REFERENCES customer(customer_id),
food_id INTEGER REFERENCES food(food_id),
order_time TIMESTAMP
);
INSERT
● Insert allows to add in rows to a table.
● No need to provide values for serial column.
Customer Table
INSERT INTO customer(name, age, email, created_on)
VALUES(‘Shravan’,24,’shravan@gmail.com’,CURRENT_TIMESTAMP);
Food Table
INSERT INTO food(name, type, created_on)
VALUES(‘Dosa’,’veg’,CURRENT_TIMESTAMP);
Order Table
INSERT INTO orders(customer_id, food_id, order_time)
VALUES(1,1,CURRENT_TIMESTAMP);
Update
● It allows for the changing of value of the columns in a table.
Update
● Update ALL Rows.
UPDATE CUSTOMER
SET age = 50 ;
Update
● Update specific row.
UPDATE CUSTOMER
SET age = 50
Where customer_id = 1 ;
Update
● Update specific row.
UPDATE CUSTOMER
SET created_on = CURRENT_TIMESTAMP
Where customer_id = 1 ;
Returning
UPDATE CUSTOMER
SET age = 50
Where customer_id = 1 ;
UPDATE CUSTOMER
SET created_on = CURRENT_TIMESTAMP
Where customer_id = 1 ;
RETURNING customer_id,age,email;
Delete
● It is used to remove all rows from a table.
DELETE FROM customer ;
Delete
● It is used to remove rows from a table.
DELETE FROM customer
Where customer_id = 1 ;
Delete + Returning
● It is used to remove rows from a table.
DELETE FROM customer
Where customer_id = 1
RETURNING customer_id, age, email;
Alter Table
1. Adding Dropping and Renaming Columns.
2. Changing a Column Data Type.
3. Set Default Values for a column.
4. Add Check Constraints.
5. Rename Table.
General Syntax
1. Adding Column
General Syntax
2. Removing Column
General Syntax
3. Alter Constraints
General Syntax
3. Alter Constraints
Drop Table
● The CASCADE option allows you to remove the table and its
dependent objects.
● The RESTRICT option rejects the removal if there is any object
depends on the table. The RESTRICT option is the default.
Drop Multiple Table
Check Constraint
Thank You
SQL Fundamentals
Part - 4
Topics
1. Aggregate Functions
2. Group By
3. Having
Aggregate Functions
● Sql provides variety of aggregate functions.
● It returns single output.
Most Common Aggregate Functions
1. AVG() Return avg value
2. COUNT() Return number of values
3. MAX() Return maximum value
4. MIN() Return minimum value
5. SUM() Return sum of all values
Aggregate Function
● Aggregate function only used with
Select Clause or having clause.
Group By
● Group By allows us to aggregate columns per some category.
Group By
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
GROUP BY category_column
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
WHERE category_col != ‘A’
GROUP BY category_column
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
WHERE category_col != ‘A’
GROUP BY category_column
ORDER BY AVG(data_col)
Group By
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE food (
food_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
type VARCHAR NOT NULL,
created_on TIMESTAMP NOT NULL
);
Select category_column, AVG(data_col)
FROM table
WHERE category_col != ‘A’
GROUP BY category_column
ORDER BY AVG(data_col)
LIMIT 5
Having
● Having Clause allows us to filter after an aggregation has already
taken place.
● To perform filtering on Group By.
Having
Select company, SUM(sales)
FROM finance_table
GROUP BY company
Having sum(sales) > 1000
Having
Select company, SUM(sales)
FROM finance_table
WHERE company != ‘Google’
GROUP BY company
Having sum(sales) > 1000
Thank You

More Related Content

What's hot

Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentationNITISH KUMAR
 
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...Edureka!
 
Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & RelationshipBellal Hossain
 
Database basics
Database basicsDatabase basics
Database basicsprachin514
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLEVraj Patel
 
java programming - applets
java programming - appletsjava programming - applets
java programming - appletsHarshithaAllu
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database ModelShishir Aryal
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Punjab University
 
9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMSkoolkampus
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLPrashant Kumar
 

What's hot (20)

Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
 
Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & Relationship
 
Database basics
Database basicsDatabase basics
Database basics
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
SQL
SQLSQL
SQL
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Triggers
TriggersTriggers
Triggers
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
 
Sql commands
Sql commandsSql commands
Sql commands
 

Similar to Bootcamp sql fundamental

Bootcamp sql fundamentals crud_part3
Bootcamp   sql fundamentals   crud_part3Bootcamp   sql fundamentals   crud_part3
Bootcamp sql fundamentals crud_part3varunbhatt23
 
Bootcamp sql fundamentals bootcamp_part1
Bootcamp   sql fundamentals  bootcamp_part1Bootcamp   sql fundamentals  bootcamp_part1
Bootcamp sql fundamentals bootcamp_part1varunbhatt23
 
Sql fundamentals group by part2
Sql fundamentals   group by part2Sql fundamentals   group by part2
Sql fundamentals group by part2varunbhatt23
 
Java class 8
Java class 8Java class 8
Java class 8Edureka!
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01sagaroceanic11
 
30 08 Final Sql
30 08 Final Sql30 08 Final Sql
30 08 Final Sqlsarov
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxjainendraKUMAR55
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1sagaroceanic11
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1Swapnali Pawar
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleFarhan Aslam
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxYashaswiniSrinivasan1
 
SQL Quick Reference Card
SQL Quick Reference CardSQL Quick Reference Card
SQL Quick Reference CardTechcanvass
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query LanguageAbhishek Gautam
 

Similar to Bootcamp sql fundamental (20)

Bootcamp sql fundamentals crud_part3
Bootcamp   sql fundamentals   crud_part3Bootcamp   sql fundamentals   crud_part3
Bootcamp sql fundamentals crud_part3
 
Bootcamp sql fundamentals bootcamp_part1
Bootcamp   sql fundamentals  bootcamp_part1Bootcamp   sql fundamentals  bootcamp_part1
Bootcamp sql fundamentals bootcamp_part1
 
Sql fundamentals group by part2
Sql fundamentals   group by part2Sql fundamentals   group by part2
Sql fundamentals group by part2
 
Java class 8
Java class 8Java class 8
Java class 8
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
30 08 Final Sql
30 08 Final Sql30 08 Final Sql
30 08 Final Sql
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
MY SQL
MY SQLMY SQL
MY SQL
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
SQL Quick Reference Card
SQL Quick Reference CardSQL Quick Reference Card
SQL Quick Reference Card
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query Language
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 

Recently uploaded (20)

Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 

Bootcamp sql fundamental

  • 2. Topics 1. Understanding Big Picture 2. Retrieving the data a. Select b. Distinct c. Count d. Where e. Order By f. Limit g. Between h. In
  • 3.
  • 4.
  • 5. Which data exactly I am talking about ?
  • 6. Where to store the data ?
  • 7.
  • 9. Why we need SQL ?
  • 10.
  • 11.
  • 12.
  • 13. Database Management System ● Databases are collections of information — or data — that have been logically modeled. ● The computer programs that interact with databases are called database management systems, or DBMSs.
  • 14. SQL Standards ● IEC — The International Electrotechnical Commission; ● ISO — The International Organization for Standardization; ● ANSI —The American National Standards Institute.
  • 15.
  • 17. Select Statement ● Used to retrieve Information Syntax : ● SELECT COLUMN_NAME FROM TABLE_NAME
  • 18. Query ● Run in a Backward Manner SELECT column1 FROM table
  • 19. Select Statement 1. SINGLE COLUMN 2. MULTIPLE COLUMN
  • 20. 1. SINGLE COLUMN ● SELECT column1 FROM table_1
  • 21. 2. MULTIPLE COLUMN ● SELECT column1, column2 FROM table_1
  • 22. ALL COLUMNS ● Get All Columns. SELECT * FROM table_1
  • 23. DISTINCT ● To list the distinct values. SELECT DISTINCT column FROM table.
  • 24. DISTINCT ● To list the distinct values. How many different continents are their ? SELECT DISTINCT(column) FROM table.
  • 25. COUNT ● Returns number of input rows that matches a specific condition of a query. Note : It won’t work without parenthesis. SELECT COUNT(column_name) FROM table_name.
  • 26. COUNT ● Count -> return number of rows ● Count is useful with other commands like distinct. HOW MANY UNIQUE NAMES ARE THERE IN THE TABLE ? SELECT COUNT(DISTINCT column_name) FROM table_name;
  • 27. WHERE ● Where statement allows us to specify condition on column for the rows. BASIC SYNTAX : SELECT column1, column2 FROM table_name WHERE condition ;
  • 30.
  • 31. Order By ● Compiler returning the output in different order each time. ● Order By is used to sort the output in ascending order or descending order. SELECT column_1, column_2 FROM table ORDER BY column_1 ASC/DESC
  • 32. LIMIT ● Limit command limit the number of rows returned for a query. ● Limit is the last command to be executed’ Select * from table_name LIMIT 2
  • 33. Between ● Used to Match the values against range of values. ○ Values Between Low and High ● Between is same as ○ Value >= low AND value <= high SELECT * FROM table_name WHERE column_1 BETWEEN low AND high
  • 34. IN ● Checks if a value is included in a list of multiple options. SELECT color FROM table_name WHERE color IN (‘red’, ‘blue’)
  • 37. Topics 1. Aggregate Functions 2. Group By 3. Having
  • 38. Aggregate Functions ● Sql provides variety of aggregate functions. ● It returns single output.
  • 39. Most Common Aggregate Functions 1. AVG() Return avg value 2. COUNT() Return number of values 3. MAX() Return maximum value 4. MIN() Return minimum value 5. SUM() Return sum of all values
  • 40. Aggregate Function ● Aggregate function only used with Select Clause or having clause.
  • 41. Group By ● Group By allows us to aggregate columns per some category.
  • 43. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table GROUP BY category_column
  • 44. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table WHERE category_col != ‘A’ GROUP BY category_column
  • 45. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table WHERE category_col != ‘A’ GROUP BY category_column ORDER BY AVG(data_col)
  • 46. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table WHERE category_col != ‘A’ GROUP BY category_column ORDER BY AVG(data_col) LIMIT 5
  • 47. Having ● Having Clause allows us to filter after an aggregation has already taken place. ● To perform filtering on Group By.
  • 48.
  • 49. Having Select company, SUM(sales) FROM finance_table GROUP BY company Having sum(sales) > 1000
  • 50. Having Select company, SUM(sales) FROM finance_table WHERE company != ‘Google’ GROUP BY company Having sum(sales) > 1000
  • 53. Topics 1. Data Types 2. Primary Keys & Foreign Keys 3. Constraints 4. Insert, Update, Delete 5. Alter Table 6. Drop Table 7. Check Constraint
  • 55.
  • 56.
  • 57. Why we need Data Types ?
  • 60.
  • 61. Data Types ● On Creating the Database & Tables, Carefully consider which data type should be used for the data to be stored. ● For Eg : ○ I want to store a phone number ○ Which Data type , it should be ?
  • 62. Which data type should we use ?
  • 63.
  • 65. Data Types ● No Arithmetic Operation
  • 66.
  • 67. Data Types ● Take time to Plan ● Modifying Table Later will be painful
  • 68. Primary Keys ● A primary key is a column or a group of columns used to identify the row uniquely in a table. ● Primary Keys helps in Joining the table.
  • 70. Why we need Primary Key ?
  • 71.
  • 72. Foreign Key ● A foreign key is a field in a table that uniquely identifies a row in another table. ● A foreign key is defined in a table that references to the primary key of the other table.
  • 73. Why we need Foreign Key ?
  • 74. Create Table ● To create Table.
  • 75.
  • 76.
  • 77. Constraints 1. Rules enforced on data columns on table.. 2. Used to prevent invalid data from being entered in the database. 3. Ensures accuracy and reliability of data.
  • 78.
  • 79. Create Table ● To create Table. CREATE TABLE table_name ( column1 datatype(length) column_contraint, column2 datatype(length) column_contraint, table_constraints );
  • 80. Create Table CREATE TABLE table_name ( CREATE TABLE table_name ( column1 datatype(length) column_contraint, column2 datatype(length) column_contraint, table_constraints ); column1 datatype(length) column_contraint, column2 datatype(length) column_contraint, table_constraints ); CREATE TABLE players ( player_id SERIAL PRIMARY KEY, age int NOT NULL );
  • 81. Serial ● It will create a sequence of the number in the increasing order. ● Used as a primary key.
  • 82. Create Table CREATE TABLE table_name ( CREATE TABLE table_name ( column1 datatype(length) column_contraint, column2 datatype(length) column_contraint, table_constraints ); column1 datatype(length) column_contraint, column2 datatype(length) column_contraint, table_constraints ); CREATE TABLE players ( player_id SERIAL PRIMARY KEY, age int NOT NULL );
  • 83. Restaurant Database 1. Customer Table 2. Food Table 3. Order Table
  • 84. Customer Table CREATE TABLE customer ( customer_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, age INT NOT NULL, email VARCHAR(50) UNIQUE NOT NULL, created_on TIMESTAMP NOT NULL );
  • 85. Food Table CREATE TABLE food ( food_id name type created_on );
  • 86. Food Table CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL );
  • 87. Order Table CREATE TABLE orders ( customer_id , food_id , Order_time );
  • 88. Order Table CREATE TABLE orders ( customer_id INTEGER REFERENCES customer(customer_id), food_id INTEGER REFERENCES food(food_id), order_time TIMESTAMP );
  • 89. INSERT ● Insert allows to add in rows to a table. ● No need to provide values for serial column.
  • 90. Customer Table INSERT INTO customer(name, age, email, created_on) VALUES(‘Shravan’,24,’shravan@gmail.com’,CURRENT_TIMESTAMP);
  • 91. Food Table INSERT INTO food(name, type, created_on) VALUES(‘Dosa’,’veg’,CURRENT_TIMESTAMP);
  • 92. Order Table INSERT INTO orders(customer_id, food_id, order_time) VALUES(1,1,CURRENT_TIMESTAMP);
  • 93. Update ● It allows for the changing of value of the columns in a table.
  • 94. Update ● Update ALL Rows. UPDATE CUSTOMER SET age = 50 ;
  • 95. Update ● Update specific row. UPDATE CUSTOMER SET age = 50 Where customer_id = 1 ;
  • 96. Update ● Update specific row. UPDATE CUSTOMER SET created_on = CURRENT_TIMESTAMP Where customer_id = 1 ;
  • 97. Returning UPDATE CUSTOMER SET age = 50 Where customer_id = 1 ; UPDATE CUSTOMER SET created_on = CURRENT_TIMESTAMP Where customer_id = 1 ; RETURNING customer_id,age,email;
  • 98. Delete ● It is used to remove all rows from a table. DELETE FROM customer ;
  • 99. Delete ● It is used to remove rows from a table. DELETE FROM customer Where customer_id = 1 ;
  • 100. Delete + Returning ● It is used to remove rows from a table. DELETE FROM customer Where customer_id = 1 RETURNING customer_id, age, email;
  • 101. Alter Table 1. Adding Dropping and Renaming Columns. 2. Changing a Column Data Type. 3. Set Default Values for a column. 4. Add Check Constraints. 5. Rename Table.
  • 104. General Syntax 3. Alter Constraints
  • 105. General Syntax 3. Alter Constraints
  • 106. Drop Table ● The CASCADE option allows you to remove the table and its dependent objects. ● The RESTRICT option rejects the removal if there is any object depends on the table. The RESTRICT option is the default.
  • 111. Topics 1. Aggregate Functions 2. Group By 3. Having
  • 112. Aggregate Functions ● Sql provides variety of aggregate functions. ● It returns single output.
  • 113. Most Common Aggregate Functions 1. AVG() Return avg value 2. COUNT() Return number of values 3. MAX() Return maximum value 4. MIN() Return minimum value 5. SUM() Return sum of all values
  • 114. Aggregate Function ● Aggregate function only used with Select Clause or having clause.
  • 115. Group By ● Group By allows us to aggregate columns per some category.
  • 117. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table GROUP BY category_column
  • 118. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table WHERE category_col != ‘A’ GROUP BY category_column
  • 119. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table WHERE category_col != ‘A’ GROUP BY category_column ORDER BY AVG(data_col)
  • 120. Group By CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); CREATE TABLE food ( food_id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, type VARCHAR NOT NULL, created_on TIMESTAMP NOT NULL ); Select category_column, AVG(data_col) FROM table WHERE category_col != ‘A’ GROUP BY category_column ORDER BY AVG(data_col) LIMIT 5
  • 121. Having ● Having Clause allows us to filter after an aggregation has already taken place. ● To perform filtering on Group By.
  • 122.
  • 123. Having Select company, SUM(sales) FROM finance_table GROUP BY company Having sum(sales) > 1000
  • 124. Having Select company, SUM(sales) FROM finance_table WHERE company != ‘Google’ GROUP BY company Having sum(sales) > 1000