SlideShare a Scribd company logo
17
Most read
18
Most read
21
Most read
1
By: Rohan Byanjankar
Sainik Awasiya Mahavidyalaya, Sallaghari, Bhaktapur
CONCEPT
ON
STRUCTURED QUERY LANGUAGE
(SQL)
2
 Structured Query Language (SQL) is the special purposed
programming language,
 Main purpose of SQL to access data in Relational Database
Management System,
 RDBMS is the most revered DBMS, and basis for SQL,
 The data in RDBMS are recorded in relations or table,
 Relation is the pre-defined rows and column, where column contains
attributes, and tuples in rows,
 Oracle, SQL Server, MySQL are the examples…
Structured Query Language
3
Major Two Languages in RDBMS
Data Definition
Language
Data Manipulation
Language
4
• One of the fundamental requirements of SQL,
• One is dumb in the SQL without knowledge of DDL,
• Backbone of SQL,
• Helps to develop overall design of database,
• Helps to create, delete, and modify the database schema,
• Not frequently used as database schema is not frequently
changed,
Data Definition Language (DDL)
5
• Create
• Use
• Drop
• Alter
Basic DDL Commands
6
One of the fundamental commands,
Use to establish many new independent database in DBMS,
Use to create table within newly established database or existing
database,
Syntax:
- CREATE DATABASE SAMB
- CREATE TABLE Students
Create Command
7
One of the fundamental commands,
Helps to work on the newly established or created database,
Syntax:
- USE SAMB
Use Command
One of the DDL commands,
Used to delete column of a table, entire table, and entire database,
We must use drop command with intense care,
Syntax:
- DROP TABLE Student
- DROP DATABASE SAMB
Drop Command
8
• Falls under the category of DDL command,
• Used to change the structure of table without deleting or re-creating
the table,
• Syntax:
1. ALTER TABLE Student
ADD Email_id VARCHAR(20)
2. ALTER TABLE Student
DROP COLUMN Email_id
Alter Command
9
• One of the fundamental requirements of SQL,
• DML helps to work on RDBMS,
• Helps to change the content of RDBMS,
• Helps to insert, select, update and delete the database
instances,
• Frequently used as frequent modification is made in database,
Data Manipulation Language (DML)
10
• Insert
• Select
• Update
• Delete
Basic DML Command
11
• Basic DML command,
• Used to add new data in database,
• The most frequently used,
Syntax:
• INERT INTO Student VALUES (0020, ‘Sujita Shrestha’, ‘BBA’,
16, ‘sujita98@gmail.com’)
• INSERT INTO Student (sid, sname, grade) VALUES (0023,
‘Smiriti KC’, ‘BBA’)
Insert Command
12
• Enables to select data from database,
• Syntax:
• To select all
• SELECT * FROM Student
• To select students with name staring from ‘S’
• SELECT * FROM Student where sname=‘s%’
• To select students according to ID in descending order
• SELECT * FROM Student
ORDER BY sid desc
Select Command
13
• Used to update existing record in a table,
• Syntax:
• UPDATE table_name SET column1= Value1
• For Example:
• To update salary to 1.5 times of existing salary of an employee
with empid 19
• UPDATE tblemployee SET salary = 1.5*salary
Update Command
WHERE empid= 19
14
• Enables us to remove the selected tuple or entire tuple without
making alter to the table,
• Syntax:
• DELETE FROM table_name WHERE column1= ‘Value1’
• For Example:
• If Student with sid 0001 is needed to be removed from Student
table, then
• DELETE FROM Student
Delete Command
WHERE sid= 0001
15
• SQL View is a logical table,
• Created from the existing table,
• Virtual table based on real table,
• Constraints of Base table is applicable in View also.
• Any modification in base table is reflected in View.
• User can Use DML commands once the view is created.
SQL Views
16
CREATE VIEW View_name AS
SELECT column1, column2, column3 FROM
Table_1 WHERE column3= ‘Value1’
For Example:
To create view from table Product (Pid, Pname, Cost Price, Selling
Price, Manu_date, Exp_date, Category) to Beverage Department
CREATE VIEW Beverage AS
SELECT Pid, Pname, Selling Price, Manu_date, Exp_date
FROM Product WHERE Category= ‘Beverage’
Syntax
17
Pid Pname Cost Price Selling Price Manu_date Exp_date Category
001 Parle-G 88 95 2014-01-05 2014-07-05 General
002 Coca-Cola 130 149 2013-12-09 2014-06-09 Beverage
003 Toberg 200 220 2013-11-14 2014-07-11 Beverage
004 Sunflow Oil 300 350 2013-08-08 2014-08-08 General
Pid Pname Selling Price Manu_date Exp_date
002 Coca-Cola 149 2013-12-09 2014-06-09
003 Toberg 220 2013-11-14 2014-07-11
Product
Beverage
CREATE VIEW Beverage AS
SELECT Pid, Pname, Selling Price, Manu_date, Exp_date
FROM Product WHERE Category= ‘Beverage’
Beverage
Department
18
• A database index is a data structure that improves the speed of
data retrieval operations on a database table,
• used to quickly locate data without having to search every row
Syntax:
CREATE INDEX index_name ON
Table_name (column1)
Index
19
For Example: To create INDEX on table Library (ISBN,
Bname, Price, Author)
CREATE INDEX Book_index ON
Library (ISBN)
Contd…
ISBN Bname Price Author
000-124-456 The Old Man and The Sea Rs. 97 Ernest Hemingway
978-1-85326-067-4 Far from the Madding Crowd Rs. 200 Thomas Hardy
978-81-291-0818-0 One Night @ The Call Center Rs. 200 Chetan Bhagat
Library
20
• Those functions that perform a calculation on a set of values and
return a single value.
• MAX, MIN, AVG, COUNT are the examples…
Syntax:
1. SELECT Column1, MAX(Column2) AS MAX_Price FROM
Tbleproduct
2. SELECT Column1, MIN(Column2) AS MIN_Price FROM
Tbleproduct
3. SELECT Column1, AVG(Column2) AS AVG_Price FROM
Tbleproduct
Aggregate Function
21
SELECT Category, MAX(Selling_Price) AS MAX_SP FROM Product
GROUP BY Category
Contd…
Pid Pname Cost_Price Selling_Price Manu_date Exp_date Category
001 Parle-G 88 95 2014-01-05 2014-07-05 General
002 Coca-Cola 130 149 2013-12-09 2014-06-09 Beverage
003 Tuborg 200 220 2013-11-14 2014-07-11 Beverage
004 Sunflow Oil 300 350 2013-08-08 2014-08-08 General
Product
Category MAX_SP
Beverage 220
General 350
22
• SQL join is the operation that enables us to get the combined
Values of attributes of two tables,
• The most common type of join is ‘Inner Join’.
Syntax:
SELECT column1, column2, column3, column5, column6 FROM
Table1
INNER JOIN Table2 ON
Table1.Column1=Table2.column5
Note:
Data type of column1 and column5 must be identical
Joins
23
ISBN Bname Price Author
000-124-456 The Old Man and The Sea Rs. 97 Ernest Hemingway
978-1-85326-067-4 Far from the Madding Crowd Rs. 200 Thomas Hardy
978-81-291-0818-0 One Night @ The Call Center Rs. 200 Chetan Bhagat
ID Sname Grade ISBN1
0001 Sanjay Sharma BBA 978-81-291-0818-0
0002 Sushil Shrestha BSC 000-124-456
0030 Samikshaya Sharma BBA 978-1-85326-067-4
Library
Student
SELECT ISBN, Bname, ID, Sname, Grade, ISBN1 FROM Library
INNER JOIN Student ON
Library.ISBN= Student.ISBN1
ISBN Bname ID Sname Grade
978-81-291-0818-0 One Night @ The Call Center 0001 Sanjay Sharma BBA
000-124-456 The Old Man and The Sea 0002 Sushil Shrestha BSC
978-1-85326-067-4 Far from the Madding Crowd 0030 Samikshaya Sharma BBA
24
Create Table Student with
following attributes:
SQL Question:
ID Number Primary Key
Name Text Not Null and
length<40
Age Number >17 and <25
Grade Text BBA or BSC
Not Null
Email Text Unique
Not Null
Contact Text Not Null
Length= 7 or 10
Address Text Not Null
CREATE TABLE Student (
ID INT,
Sname VARCHAR (50) NOT NULL,
Age INT,
Grade VARCHAR (8) NOT NULL,
Email_id VARCHAR (30) UNIQUE NOT NULL,
Contact VARCHAR (13) NOT NULL,
Address VARCHAR (30) NOT NULL,
CONSTRAINT pk_id PRIMARY KEY (ID),
CONSTRAINT ch_values CHECK
(LEN(Sname)<40),
CONSTRAINT ch_values1 CHECK(Grade IN
(‘BBA’,’BSC’)),
CONSTRAINT ch_values2 CHECK
(LEN(Contact)=7 OR LEN(Contact)=10));

More Related Content

PDF
Oracle SQL Basics
PPT
Sql views
ODP
PPT
PPT
SQL subquery
PPTX
Sql(structured query language)
PPT
PPTX
Oracle: Joins
Oracle SQL Basics
Sql views
SQL subquery
Sql(structured query language)
Oracle: Joins

What's hot (20)

PPTX
Chapter 1 introduction to sql server
PPTX
SQL - DML and DDL Commands
PPTX
PPTX
SQLite - Overview
PPTX
STRUCTURE OF SQL QUERIES
PPT
PL/SQL Introduction and Concepts
PPTX
introdution to SQL and SQL functions
PPT
1 - Introduction to PL/SQL
PPT
Joins in SQL
PPT
Collections in Java
PPTX
Sql commands
PPTX
Intro to DAX Patterns
ODP
OOP java
PPTX
SQL - Structured query language introduction
PPTX
Basic Concept of Database
PPT
Oracle PLSQL Step By Step Guide
PDF
Oracle sql & plsql
ODP
Introduction to triggers
PPT
MySql slides (ppt)
PPTX
Project Presentation on Advance Java
Chapter 1 introduction to sql server
SQL - DML and DDL Commands
SQLite - Overview
STRUCTURE OF SQL QUERIES
PL/SQL Introduction and Concepts
introdution to SQL and SQL functions
1 - Introduction to PL/SQL
Joins in SQL
Collections in Java
Sql commands
Intro to DAX Patterns
OOP java
SQL - Structured query language introduction
Basic Concept of Database
Oracle PLSQL Step By Step Guide
Oracle sql & plsql
Introduction to triggers
MySql slides (ppt)
Project Presentation on Advance Java
Ad

Viewers also liked (19)

PPTX
Structured Query Language (SQL)
PPT
Análisis y perspectivas del cluster canalero
PPTX
Farmacocinética
PDF
OPIM FINAL TURN IN
PDF
Whitmore Sonja 3.3
PDF
HFH Who We Are_Hi-Res
PPTX
taller #1 power point-apudep4
PPTX
My vacations erika mayerly
DOC
LinkedIn Profile template
PDF
700 dinámicas
DOC
mena george
PDF
Consumer Behavior Project
PDF
Rosie BDCH artwork
PDF
sidewinders
PDF
DOS Chip Moreland M28 EE
PDF
KEI_Book_Sample
PPTX
Consumer Behavior Lab
PPTX
How to sharpen skis
PPTX
PROYECTO DE VIDA INVESTIGACIÓN CIENCIA Y TECNOLOGIA
Structured Query Language (SQL)
Análisis y perspectivas del cluster canalero
Farmacocinética
OPIM FINAL TURN IN
Whitmore Sonja 3.3
HFH Who We Are_Hi-Res
taller #1 power point-apudep4
My vacations erika mayerly
LinkedIn Profile template
700 dinámicas
mena george
Consumer Behavior Project
Rosie BDCH artwork
sidewinders
DOS Chip Moreland M28 EE
KEI_Book_Sample
Consumer Behavior Lab
How to sharpen skis
PROYECTO DE VIDA INVESTIGACIÓN CIENCIA Y TECNOLOGIA
Ad

Similar to Concept of Structured Query Language (SQL) in SQL server as well as MySql. BBA 2nd Semester, Tribhuvan University. (20)

PPTX
Avinash database
PDF
SQL for data scientist And data analysist Advanced
PPTX
MS SQL - Database Programming Concepts by RSolutions
PPTX
Relational Database Language.pptx
PPT
Db1 lecture4
PDF
STRUCTURED QUERY LANGUAGE
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
PPT
Sql Commands_Dr.R.Shalini.ppt
PPT
Review of SQL
PPT
Ch 9 S Q L
PPTX
SQL: Data Definition Language(DDL) command
PPT
dbs class 7.ppt
PPTX
SQL(database)
PPTX
PPT
Introduction to Structured Query Language (SQL) (1).ppt
PPT
Lec 1 = introduction to structured query language (sql)
PPT
15925 structured query
PPTX
Introduction to database and sql fir beginers
Avinash database
SQL for data scientist And data analysist Advanced
MS SQL - Database Programming Concepts by RSolutions
Relational Database Language.pptx
Db1 lecture4
STRUCTURED QUERY LANGUAGE
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
Sql Commands_Dr.R.Shalini.ppt
Review of SQL
Ch 9 S Q L
SQL: Data Definition Language(DDL) command
dbs class 7.ppt
SQL(database)
Introduction to Structured Query Language (SQL) (1).ppt
Lec 1 = introduction to structured query language (sql)
15925 structured query
Introduction to database and sql fir beginers

More from Rohan Byanjankar (19)

PDF
12 Reasons for Never, Ever carrying out Data Analysis
PDF
Concept of annuity
PPSX
Risk Associated with Derivative Markets
PDF
Relationship between Average Revenue (AR), Marginal Revenue (MR), and Elastic...
PDF
Multiplier: Concept, Types, and Derivation of each type of Multiplier
PPTX
Origin of Nepal: Nepal as a Sovereign Country
PPSX
Understanding Interest Rate Swap: Price of Interest Rate Swap and Value of In...
PPTX
Human Development Index; Components of Human Development Index, Significance ...
DOCX
A Study on Online Health Service at HamroDoctor
DOCX
Siddhi Memorial Foundation, Bhaktapur, Nepal
DOCX
Trade and Export Promotion Centre, Nepal
DOCX
Introduction to HASERA
PPTX
Sociology and Religion: Religion as a Social Institution
PPTX
Inductive and Deductive Approach to Research. Difference between Inductive an...
PPTX
Online Business; What is E-commerce; What are the points to be considered whi...
PPTX
NEPAL; Demographic Analysis of Nepal; Comparative Study of Various Census and...
PPTX
Concept of Relational Database and Integrity Constraints [DIFFERENCE BETWEEN ...
PDF
Microeconomics: Concept of Indifference Curve and Budget Line. Definition of ...
PPTX
Difference between selling concept and marketing concept
12 Reasons for Never, Ever carrying out Data Analysis
Concept of annuity
Risk Associated with Derivative Markets
Relationship between Average Revenue (AR), Marginal Revenue (MR), and Elastic...
Multiplier: Concept, Types, and Derivation of each type of Multiplier
Origin of Nepal: Nepal as a Sovereign Country
Understanding Interest Rate Swap: Price of Interest Rate Swap and Value of In...
Human Development Index; Components of Human Development Index, Significance ...
A Study on Online Health Service at HamroDoctor
Siddhi Memorial Foundation, Bhaktapur, Nepal
Trade and Export Promotion Centre, Nepal
Introduction to HASERA
Sociology and Religion: Religion as a Social Institution
Inductive and Deductive Approach to Research. Difference between Inductive an...
Online Business; What is E-commerce; What are the points to be considered whi...
NEPAL; Demographic Analysis of Nepal; Comparative Study of Various Census and...
Concept of Relational Database and Integrity Constraints [DIFFERENCE BETWEEN ...
Microeconomics: Concept of Indifference Curve and Budget Line. Definition of ...
Difference between selling concept and marketing concept

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Presentation on HIE in infants and its manifestations
PPTX
Cell Types and Its function , kingdom of life
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
master seminar digital applications in india
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Cell Structure & Organelles in detailed.
PDF
Complications of Minimal Access Surgery at WLH
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
GDM (1) (1).pptx small presentation for students
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Presentation on HIE in infants and its manifestations
Cell Types and Its function , kingdom of life
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
master seminar digital applications in india
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Structure & Organelles in detailed.
Complications of Minimal Access Surgery at WLH
Chinmaya Tiranga quiz Grand Finale.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
GDM (1) (1).pptx small presentation for students

Concept of Structured Query Language (SQL) in SQL server as well as MySql. BBA 2nd Semester, Tribhuvan University.

  • 1. 1 By: Rohan Byanjankar Sainik Awasiya Mahavidyalaya, Sallaghari, Bhaktapur CONCEPT ON STRUCTURED QUERY LANGUAGE (SQL)
  • 2. 2  Structured Query Language (SQL) is the special purposed programming language,  Main purpose of SQL to access data in Relational Database Management System,  RDBMS is the most revered DBMS, and basis for SQL,  The data in RDBMS are recorded in relations or table,  Relation is the pre-defined rows and column, where column contains attributes, and tuples in rows,  Oracle, SQL Server, MySQL are the examples… Structured Query Language
  • 3. 3 Major Two Languages in RDBMS Data Definition Language Data Manipulation Language
  • 4. 4 • One of the fundamental requirements of SQL, • One is dumb in the SQL without knowledge of DDL, • Backbone of SQL, • Helps to develop overall design of database, • Helps to create, delete, and modify the database schema, • Not frequently used as database schema is not frequently changed, Data Definition Language (DDL)
  • 5. 5 • Create • Use • Drop • Alter Basic DDL Commands
  • 6. 6 One of the fundamental commands, Use to establish many new independent database in DBMS, Use to create table within newly established database or existing database, Syntax: - CREATE DATABASE SAMB - CREATE TABLE Students Create Command
  • 7. 7 One of the fundamental commands, Helps to work on the newly established or created database, Syntax: - USE SAMB Use Command One of the DDL commands, Used to delete column of a table, entire table, and entire database, We must use drop command with intense care, Syntax: - DROP TABLE Student - DROP DATABASE SAMB Drop Command
  • 8. 8 • Falls under the category of DDL command, • Used to change the structure of table without deleting or re-creating the table, • Syntax: 1. ALTER TABLE Student ADD Email_id VARCHAR(20) 2. ALTER TABLE Student DROP COLUMN Email_id Alter Command
  • 9. 9 • One of the fundamental requirements of SQL, • DML helps to work on RDBMS, • Helps to change the content of RDBMS, • Helps to insert, select, update and delete the database instances, • Frequently used as frequent modification is made in database, Data Manipulation Language (DML)
  • 10. 10 • Insert • Select • Update • Delete Basic DML Command
  • 11. 11 • Basic DML command, • Used to add new data in database, • The most frequently used, Syntax: • INERT INTO Student VALUES (0020, ‘Sujita Shrestha’, ‘BBA’, 16, ‘sujita98@gmail.com’) • INSERT INTO Student (sid, sname, grade) VALUES (0023, ‘Smiriti KC’, ‘BBA’) Insert Command
  • 12. 12 • Enables to select data from database, • Syntax: • To select all • SELECT * FROM Student • To select students with name staring from ‘S’ • SELECT * FROM Student where sname=‘s%’ • To select students according to ID in descending order • SELECT * FROM Student ORDER BY sid desc Select Command
  • 13. 13 • Used to update existing record in a table, • Syntax: • UPDATE table_name SET column1= Value1 • For Example: • To update salary to 1.5 times of existing salary of an employee with empid 19 • UPDATE tblemployee SET salary = 1.5*salary Update Command WHERE empid= 19
  • 14. 14 • Enables us to remove the selected tuple or entire tuple without making alter to the table, • Syntax: • DELETE FROM table_name WHERE column1= ‘Value1’ • For Example: • If Student with sid 0001 is needed to be removed from Student table, then • DELETE FROM Student Delete Command WHERE sid= 0001
  • 15. 15 • SQL View is a logical table, • Created from the existing table, • Virtual table based on real table, • Constraints of Base table is applicable in View also. • Any modification in base table is reflected in View. • User can Use DML commands once the view is created. SQL Views
  • 16. 16 CREATE VIEW View_name AS SELECT column1, column2, column3 FROM Table_1 WHERE column3= ‘Value1’ For Example: To create view from table Product (Pid, Pname, Cost Price, Selling Price, Manu_date, Exp_date, Category) to Beverage Department CREATE VIEW Beverage AS SELECT Pid, Pname, Selling Price, Manu_date, Exp_date FROM Product WHERE Category= ‘Beverage’ Syntax
  • 17. 17 Pid Pname Cost Price Selling Price Manu_date Exp_date Category 001 Parle-G 88 95 2014-01-05 2014-07-05 General 002 Coca-Cola 130 149 2013-12-09 2014-06-09 Beverage 003 Toberg 200 220 2013-11-14 2014-07-11 Beverage 004 Sunflow Oil 300 350 2013-08-08 2014-08-08 General Pid Pname Selling Price Manu_date Exp_date 002 Coca-Cola 149 2013-12-09 2014-06-09 003 Toberg 220 2013-11-14 2014-07-11 Product Beverage CREATE VIEW Beverage AS SELECT Pid, Pname, Selling Price, Manu_date, Exp_date FROM Product WHERE Category= ‘Beverage’ Beverage Department
  • 18. 18 • A database index is a data structure that improves the speed of data retrieval operations on a database table, • used to quickly locate data without having to search every row Syntax: CREATE INDEX index_name ON Table_name (column1) Index
  • 19. 19 For Example: To create INDEX on table Library (ISBN, Bname, Price, Author) CREATE INDEX Book_index ON Library (ISBN) Contd… ISBN Bname Price Author 000-124-456 The Old Man and The Sea Rs. 97 Ernest Hemingway 978-1-85326-067-4 Far from the Madding Crowd Rs. 200 Thomas Hardy 978-81-291-0818-0 One Night @ The Call Center Rs. 200 Chetan Bhagat Library
  • 20. 20 • Those functions that perform a calculation on a set of values and return a single value. • MAX, MIN, AVG, COUNT are the examples… Syntax: 1. SELECT Column1, MAX(Column2) AS MAX_Price FROM Tbleproduct 2. SELECT Column1, MIN(Column2) AS MIN_Price FROM Tbleproduct 3. SELECT Column1, AVG(Column2) AS AVG_Price FROM Tbleproduct Aggregate Function
  • 21. 21 SELECT Category, MAX(Selling_Price) AS MAX_SP FROM Product GROUP BY Category Contd… Pid Pname Cost_Price Selling_Price Manu_date Exp_date Category 001 Parle-G 88 95 2014-01-05 2014-07-05 General 002 Coca-Cola 130 149 2013-12-09 2014-06-09 Beverage 003 Tuborg 200 220 2013-11-14 2014-07-11 Beverage 004 Sunflow Oil 300 350 2013-08-08 2014-08-08 General Product Category MAX_SP Beverage 220 General 350
  • 22. 22 • SQL join is the operation that enables us to get the combined Values of attributes of two tables, • The most common type of join is ‘Inner Join’. Syntax: SELECT column1, column2, column3, column5, column6 FROM Table1 INNER JOIN Table2 ON Table1.Column1=Table2.column5 Note: Data type of column1 and column5 must be identical Joins
  • 23. 23 ISBN Bname Price Author 000-124-456 The Old Man and The Sea Rs. 97 Ernest Hemingway 978-1-85326-067-4 Far from the Madding Crowd Rs. 200 Thomas Hardy 978-81-291-0818-0 One Night @ The Call Center Rs. 200 Chetan Bhagat ID Sname Grade ISBN1 0001 Sanjay Sharma BBA 978-81-291-0818-0 0002 Sushil Shrestha BSC 000-124-456 0030 Samikshaya Sharma BBA 978-1-85326-067-4 Library Student SELECT ISBN, Bname, ID, Sname, Grade, ISBN1 FROM Library INNER JOIN Student ON Library.ISBN= Student.ISBN1 ISBN Bname ID Sname Grade 978-81-291-0818-0 One Night @ The Call Center 0001 Sanjay Sharma BBA 000-124-456 The Old Man and The Sea 0002 Sushil Shrestha BSC 978-1-85326-067-4 Far from the Madding Crowd 0030 Samikshaya Sharma BBA
  • 24. 24 Create Table Student with following attributes: SQL Question: ID Number Primary Key Name Text Not Null and length<40 Age Number >17 and <25 Grade Text BBA or BSC Not Null Email Text Unique Not Null Contact Text Not Null Length= 7 or 10 Address Text Not Null CREATE TABLE Student ( ID INT, Sname VARCHAR (50) NOT NULL, Age INT, Grade VARCHAR (8) NOT NULL, Email_id VARCHAR (30) UNIQUE NOT NULL, Contact VARCHAR (13) NOT NULL, Address VARCHAR (30) NOT NULL, CONSTRAINT pk_id PRIMARY KEY (ID), CONSTRAINT ch_values CHECK (LEN(Sname)<40), CONSTRAINT ch_values1 CHECK(Grade IN (‘BBA’,’BSC’)), CONSTRAINT ch_values2 CHECK (LEN(Contact)=7 OR LEN(Contact)=10));