SlideShare a Scribd company logo
DATA BASE MANAGEMENT
SYSTEMS
Basic queiries in sql
By : Nagashayan Reddy
V th sem, Deptof ISE
SJC INSTITUTE OF
TECHNOLOGY
CHICKBALLAPUR-562101
Jai sri gurudev
Sql
1. Introduction
2. SELECT-FROM-WHERE Structure
3. Ambiguous Attribute Names,Aliasing,and Tuple
variables
4. Unspecified WHERE Clause and Use of Asterisk
5. Tables as sets in SQL
6. Substring Pattern Matching and Arithmetic
Operators
7. Ordering of Query Results
First Concept:
1. Introduction
Defination of Queries:
• Definition: Queries are the primary
mechanism for retrieving information from a
database and consist of questions presented
to the database in a predefined format. Many
database management systems use the
Structured Query Language (SQL) standard
query format.
Example:-
Sql
Sql
Sql
Sql
Sql
1. SQL has one basic statement for retrieving
information from database: SELECT statement
2. The SELECT statement has no relationship to the
SELECT operation of relational algebra
3. SQL table is not a set of tuples,because set
doesnot allow two identical members.
4. We will call SQL table as a multiset(sometimes
called a bag) of tuples.
Second Cocept:
2. SELECT-FROM-
WHERE
STRUCTURE
• ANY QUERIES IN SQL WILL BE IN THE FOLLOWING
FORM:-
SELECT [DISTINCT] <ATTRIBUTE LIST>
FROM <TABLE LIST>
WHERE<CONDITION>;
• Such a query intuitively corresponds to a relational
algebra expression, involving selections,projections,
& cross products.
• CONCEPTUAL EVALUATION STATERGY OF SELECTOPERATION:
1. Computethe cross product of the tables in the from_list
2. Deletethose rows in thecross-product thatfailthe qualification
conditions
3. Deleteallcoloumns thatdo not appear in the select-list
4. If distinct isspecified,eliminateduplicate rows
BAGEPALLY_UNION
NAME ADDRESS
FAMILY
INCOME
NAGA
SHAYANA
REDDY
NETHAJI
CIRCLE,
BAGEPALLY
100000
MAHESHA NATIONAL
COLLEGE,
BAGEPALLY
100000
VENKATEH
NAIK
PENUMALE
,BAGEPALY 150000
MEHR TAJ 21ST
WARD,
BAGEPALLY
250000000
0000
SHRAVANI GULUR,
BAGEPALLY
230000
SUSHMA
REDDY
JILAKARAP
ALLY,
235000
BNO
1
2
3
4
5
6
UNION_INFO
BNO AGGREGATES(%)
1. 65
2. 58
3. 64
4. 68
5. 66
6. 69
• TIPS FOR WRITING QUIERIES
• 1. As soon as Query is given first we have
• to make a note that what are the tables
involving in this
2. After getting an idea about tables we
have to search for a link attribute
3. we have to write a relational algebra
first
4. Then converting a same to quierie
• Quierie : Get the names of all the students who
have the greater than 200000 family income
Relational algebra:
π NAME[σ FAMILY INCOME>200000 (bagepally_union) ]
SQL QUIERIE
SELECT NAME
FROM BAGEPALLY_UNION
WHERE FAMILY INCOME>200000
Concept 3:-
Ambigious Attribute
Names,Aliasing, and tuple
Variables
• IN SQL AMBIGUITY WILL ARRISES MAINLY IN
TWO DIFFERENT CASES:-
1. Using same name for two attributes that are
there in two different relations
2. Quieries that referring to a same relation twice
•
• QUERY 1:
Retrieve the names of the students who have
above 60% aggreate:
Relational algebra:
π NAME[ σagregate>60 (bagepally_union ⋈bno=bno union_info) ]
• SQL QUIERIE:
Select name
From bagepally_union as b,
union_info as u
Where b.bno=u.bno
•
 1. Aliases are the alternative relation
 names

 2. Aliases can also called as tuple
 variable
• Concept Four:
• Unspecified Where clause
• and use of asterisk
•
1. If WHERE condition is missing in Quierie
all the tuples that are specified in the FROM
will retrieved
2. It will become problamatic if two or more rela
-tions are specified it will make to retrieve
all the possibilities of the cartesian product.
• To Rerieve all the attribute values of the
selected tuples,we do not have to list the
attribute names explicitly in SQL
• We just specify an asterisk(*) which means that
all the attributes
• Querie:
select *
from bagepally_union
• CONCEPT 4:
SUBSTRING PATTERN MATCHING AND ARITHMETIC
OPERATORS
• SQL provides the facility to the programmers to
have pattern matching features in the data base
• It also gives the flexibility in using arithmetic
operations for data base
• The first feature allows comparision conditions on
only parts of a character string, by using the LIKE
comparision operation
• This LIKE operation can be used for string pattern
matching
• Partial keys in the quieries arer specified using two
reserve characters:% ,_
• % can be used as follows
select address
from bagepally_union
where name like‘%mehr taj%’
• _ can be used as follows
selcect address
from bagepally_union
where family income like ‘2_______’
• ORDERING OF QUERY RESULTS
1. SQL allows the user to order the tuples in the
resulot of a query by the values of one or more
attributes,using ORDER BY clause. This can be
illustrated as follows
Select name,address
From bagepally_union as b,
union_info as u
Where b.bno=u.bno
order by address,name
Sql
Sql

More Related Content

PPTX
Introduction to dbms
Umamaheshwariv1
 
PPTX
Referential integrity
Jubin Raju
 
PDF
LinkedList vs ArrayList in Java | Edureka
Edureka!
 
PPTX
SQL : Structured Query Language
Abhishek Gautam
 
ODP
Mysql database
mayank78634
 
PDF
Dms 22319 micro project
ARVIND SARDAR
 
PPTX
Sql(structured query language)
Ishucs
 
PPTX
Data Manipulation Language
Jas Singh Bhasin
 
Introduction to dbms
Umamaheshwariv1
 
Referential integrity
Jubin Raju
 
LinkedList vs ArrayList in Java | Edureka
Edureka!
 
SQL : Structured Query Language
Abhishek Gautam
 
Mysql database
mayank78634
 
Dms 22319 micro project
ARVIND SARDAR
 
Sql(structured query language)
Ishucs
 
Data Manipulation Language
Jas Singh Bhasin
 

What's hot (19)

PPTX
STRUCTURE OF SQL QUERIES
VENNILAV6
 
PPTX
Relational Database Management System part II
KavithaA19
 
PDF
Dbms Interview Question And Answer
Jagan Mohan Bishoyi
 
PPT
Relational model
WBUTTUTORIALS
 
PPTX
advanced sql(database)
welcometofacebook
 
PPT
Lecture 07 relational database management system
emailharmeet
 
PPTX
Relational data model
Vaishali Chinchkhede
 
PPT
Advanced Sql Training
bixxman
 
PPT
Stoop 434-composite
The World of Smalltalk
 
PPTX
Class diagram
SESP123
 
PPTX
Relational model
Sabana Maharjan
 
PPTX
The relational database model chapter 2
Nargis Ehsan
 
PDF
Sql interview-book
Vipul Wankar
 
PDF
Assignment#05
Sunita Milind Dol
 
PPTX
SQL Basics
Hammad Rasheed
 
PDF
SQLite Database Tutorial In Android
Android 5
 
PPTX
Db pre
frrobin
 
PPT
Class diagram
Praneeth Yadav
 
STRUCTURE OF SQL QUERIES
VENNILAV6
 
Relational Database Management System part II
KavithaA19
 
Dbms Interview Question And Answer
Jagan Mohan Bishoyi
 
Relational model
WBUTTUTORIALS
 
advanced sql(database)
welcometofacebook
 
Lecture 07 relational database management system
emailharmeet
 
Relational data model
Vaishali Chinchkhede
 
Advanced Sql Training
bixxman
 
Stoop 434-composite
The World of Smalltalk
 
Class diagram
SESP123
 
Relational model
Sabana Maharjan
 
The relational database model chapter 2
Nargis Ehsan
 
Sql interview-book
Vipul Wankar
 
Assignment#05
Sunita Milind Dol
 
SQL Basics
Hammad Rasheed
 
SQLite Database Tutorial In Android
Android 5
 
Db pre
frrobin
 
Class diagram
Praneeth Yadav
 
Ad

Viewers also liked (16)

PPTX
Ximena computacion
Xime Lerma
 
PDF
LINKEDIN: Êtes vous prêt à utiliser tout son potentiel en 2017
Didier SAVALLE
 
PDF
Cevap Anahtarlari 1 35
itu
 
PDF
Solution inc(speakers)
yadavadevil
 
PDF
Peter VanPelt
OPUNITE
 
PDF
Stress Testing Masterclass Johnk
Trueventus
 
PPTX
Lk 03
jayus jayus yus
 
PDF
ACOOK_portfolio
Alexandra Cook
 
PPTX
Plan de trabajo
Tormex Industrias S.A. de C.V.
 
PPS
2 一定赢0917
Bill Li
 
PPTX
K-10714 ABHISHEK(TQM )
shailesh yadav
 
PPT
Img prod comp.030914
impactwithkangen
 
PDF
28/09/2016 - Communiqué de presse Orpéa
Yves Le Masne
 
PPTX
Plan de investigación
Felixman25
 
PDF
E wthe littlleredhenandthperfectedeapplepie
lnash1
 
PPT
Recso
JISC Netskills
 
Ximena computacion
Xime Lerma
 
LINKEDIN: Êtes vous prêt à utiliser tout son potentiel en 2017
Didier SAVALLE
 
Cevap Anahtarlari 1 35
itu
 
Solution inc(speakers)
yadavadevil
 
Peter VanPelt
OPUNITE
 
Stress Testing Masterclass Johnk
Trueventus
 
ACOOK_portfolio
Alexandra Cook
 
2 一定赢0917
Bill Li
 
K-10714 ABHISHEK(TQM )
shailesh yadav
 
Img prod comp.030914
impactwithkangen
 
28/09/2016 - Communiqué de presse Orpéa
Yves Le Masne
 
Plan de investigación
Felixman25
 
E wthe littlleredhenandthperfectedeapplepie
lnash1
 
Ad

Similar to Sql (20)

PPTX
SQL data types: INT, VARCHAR, CHAR,.pptx
dharaneshgopal
 
PPT
SQL.ppt
RickyLidar
 
PPT
UNIT 2 Structured query language commands
Bhakti Pawar
 
PPT
mysql.ppt
nawaz65
 
PPTX
Server Query Language – Getting Started.pptx
auzee32
 
PPTX
U-2.pptx igxitditdursruzyezrzmyayeTeYrsyrsurzursursursursursrusursruzruRuUeYe...
dagadsai0330
 
PDF
04-Intro-SQL database management systems
ArmanHarun2221777642
 
PPT
Relational algebra.pptx
RUpaliLohar
 
PPT
04.SQL.ppt
suchithreddyvemula
 
PPT
04 Introduction to SQ(Structural Query Language)L.ppt
ShishirOyshi20143346
 
PPT
Chapter08
sasa_eldoby
 
PPTX
DB2 Sql Query
Hari Christian
 
PPTX
Its about a sql topic for basic structured query language
IMsKanchanaI
 
PDF
Sql (Introduction to Structured Query language)
Mohd Tousif
 
PPTX
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
PPTX
Lecture8-SQL-PartI-Jan30-2018 test Lecture8-SQL-PartI-Jan30-2018 test
ssuser9dddf7
 
PPTX
vnd.openxmlformats-officedocument.presentationml.presentation&rendition=1.pptx
jaijsr12345
 
PPTX
1. dml select statement reterive data
Amrit Kaur
 
PPTX
Dbms sql-final
NV Chandra Sekhar Nittala
 
SQL data types: INT, VARCHAR, CHAR,.pptx
dharaneshgopal
 
SQL.ppt
RickyLidar
 
UNIT 2 Structured query language commands
Bhakti Pawar
 
mysql.ppt
nawaz65
 
Server Query Language – Getting Started.pptx
auzee32
 
U-2.pptx igxitditdursruzyezrzmyayeTeYrsyrsurzursursursursursrusursruzruRuUeYe...
dagadsai0330
 
04-Intro-SQL database management systems
ArmanHarun2221777642
 
Relational algebra.pptx
RUpaliLohar
 
04.SQL.ppt
suchithreddyvemula
 
04 Introduction to SQ(Structural Query Language)L.ppt
ShishirOyshi20143346
 
Chapter08
sasa_eldoby
 
DB2 Sql Query
Hari Christian
 
Its about a sql topic for basic structured query language
IMsKanchanaI
 
Sql (Introduction to Structured Query language)
Mohd Tousif
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
Lecture8-SQL-PartI-Jan30-2018 test Lecture8-SQL-PartI-Jan30-2018 test
ssuser9dddf7
 
vnd.openxmlformats-officedocument.presentationml.presentation&rendition=1.pptx
jaijsr12345
 
1. dml select statement reterive data
Amrit Kaur
 

Recently uploaded (20)

PPTX
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
Inventory management chapter in automation and robotics.
atisht0104
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
Zero Carbon Building Performance standard
BassemOsman1
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 

Sql

  • 1. DATA BASE MANAGEMENT SYSTEMS Basic queiries in sql By : Nagashayan Reddy V th sem, Deptof ISE SJC INSTITUTE OF TECHNOLOGY CHICKBALLAPUR-562101 Jai sri gurudev
  • 3. 1. Introduction 2. SELECT-FROM-WHERE Structure 3. Ambiguous Attribute Names,Aliasing,and Tuple variables 4. Unspecified WHERE Clause and Use of Asterisk 5. Tables as sets in SQL 6. Substring Pattern Matching and Arithmetic Operators 7. Ordering of Query Results
  • 5. Defination of Queries: • Definition: Queries are the primary mechanism for retrieving information from a database and consist of questions presented to the database in a predefined format. Many database management systems use the Structured Query Language (SQL) standard query format.
  • 12. 1. SQL has one basic statement for retrieving information from database: SELECT statement 2. The SELECT statement has no relationship to the SELECT operation of relational algebra 3. SQL table is not a set of tuples,because set doesnot allow two identical members. 4. We will call SQL table as a multiset(sometimes called a bag) of tuples.
  • 14. • ANY QUERIES IN SQL WILL BE IN THE FOLLOWING FORM:- SELECT [DISTINCT] <ATTRIBUTE LIST> FROM <TABLE LIST> WHERE<CONDITION>; • Such a query intuitively corresponds to a relational algebra expression, involving selections,projections, & cross products.
  • 15. • CONCEPTUAL EVALUATION STATERGY OF SELECTOPERATION: 1. Computethe cross product of the tables in the from_list 2. Deletethose rows in thecross-product thatfailthe qualification conditions 3. Deleteallcoloumns thatdo not appear in the select-list 4. If distinct isspecified,eliminateduplicate rows
  • 16. BAGEPALLY_UNION NAME ADDRESS FAMILY INCOME NAGA SHAYANA REDDY NETHAJI CIRCLE, BAGEPALLY 100000 MAHESHA NATIONAL COLLEGE, BAGEPALLY 100000 VENKATEH NAIK PENUMALE ,BAGEPALY 150000 MEHR TAJ 21ST WARD, BAGEPALLY 250000000 0000 SHRAVANI GULUR, BAGEPALLY 230000 SUSHMA REDDY JILAKARAP ALLY, 235000 BNO 1 2 3 4 5 6 UNION_INFO BNO AGGREGATES(%) 1. 65 2. 58 3. 64 4. 68 5. 66 6. 69
  • 17. • TIPS FOR WRITING QUIERIES • 1. As soon as Query is given first we have • to make a note that what are the tables involving in this 2. After getting an idea about tables we have to search for a link attribute 3. we have to write a relational algebra first 4. Then converting a same to quierie
  • 18. • Quierie : Get the names of all the students who have the greater than 200000 family income Relational algebra: π NAME[σ FAMILY INCOME>200000 (bagepally_union) ] SQL QUIERIE SELECT NAME FROM BAGEPALLY_UNION WHERE FAMILY INCOME>200000
  • 20. • IN SQL AMBIGUITY WILL ARRISES MAINLY IN TWO DIFFERENT CASES:- 1. Using same name for two attributes that are there in two different relations 2. Quieries that referring to a same relation twice
  • 21. • • QUERY 1: Retrieve the names of the students who have above 60% aggreate: Relational algebra: π NAME[ σagregate>60 (bagepally_union ⋈bno=bno union_info) ]
  • 22. • SQL QUIERIE: Select name From bagepally_union as b, union_info as u Where b.bno=u.bno
  • 23. •  1. Aliases are the alternative relation  names   2. Aliases can also called as tuple  variable
  • 24. • Concept Four: • Unspecified Where clause • and use of asterisk •
  • 25. 1. If WHERE condition is missing in Quierie all the tuples that are specified in the FROM will retrieved 2. It will become problamatic if two or more rela -tions are specified it will make to retrieve all the possibilities of the cartesian product.
  • 26. • To Rerieve all the attribute values of the selected tuples,we do not have to list the attribute names explicitly in SQL • We just specify an asterisk(*) which means that all the attributes • Querie: select * from bagepally_union
  • 27. • CONCEPT 4: SUBSTRING PATTERN MATCHING AND ARITHMETIC OPERATORS
  • 28. • SQL provides the facility to the programmers to have pattern matching features in the data base • It also gives the flexibility in using arithmetic operations for data base • The first feature allows comparision conditions on only parts of a character string, by using the LIKE comparision operation • This LIKE operation can be used for string pattern matching • Partial keys in the quieries arer specified using two reserve characters:% ,_
  • 29. • % can be used as follows select address from bagepally_union where name like‘%mehr taj%’ • _ can be used as follows selcect address from bagepally_union where family income like ‘2_______’
  • 30. • ORDERING OF QUERY RESULTS 1. SQL allows the user to order the tuples in the resulot of a query by the values of one or more attributes,using ORDER BY clause. This can be illustrated as follows Select name,address From bagepally_union as b, union_info as u Where b.bno=u.bno order by address,name