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
PPTX
Referential integrity
PDF
LinkedList vs ArrayList in Java | Edureka
PPTX
SQL : Structured Query Language
ODP
Mysql database
PDF
Dms 22319 micro project
PPTX
Sql(structured query language)
PPTX
Data Manipulation Language
Introduction to dbms
Referential integrity
LinkedList vs ArrayList in Java | Edureka
SQL : Structured Query Language
Mysql database
Dms 22319 micro project
Sql(structured query language)
Data Manipulation Language

What's hot (19)

PPTX
STRUCTURE OF SQL QUERIES
PPTX
Relational Database Management System part II
PDF
Dbms Interview Question And Answer
PPT
Relational model
PPTX
advanced sql(database)
PPT
Lecture 07 relational database management system
PPTX
Relational data model
PPT
Advanced Sql Training
PPT
Stoop 434-composite
PPTX
Class diagram
PPTX
Relational model
PPTX
The relational database model chapter 2
PDF
Sql interview-book
PDF
Assignment#05
PPTX
SQL Basics
PDF
SQLite Database Tutorial In Android
PPTX
Db pre
PPT
Class diagram
STRUCTURE OF SQL QUERIES
Relational Database Management System part II
Dbms Interview Question And Answer
Relational model
advanced sql(database)
Lecture 07 relational database management system
Relational data model
Advanced Sql Training
Stoop 434-composite
Class diagram
Relational model
The relational database model chapter 2
Sql interview-book
Assignment#05
SQL Basics
SQLite Database Tutorial In Android
Db pre
Class diagram
Ad

Viewers also liked (16)

PPTX
Ximena computacion
PDF
LINKEDIN: Êtes vous prêt à utiliser tout son potentiel en 2017
PDF
Cevap Anahtarlari 1 35
 
PDF
Solution inc(speakers)
PDF
Peter VanPelt
PDF
Stress Testing Masterclass Johnk
PPTX
PDF
ACOOK_portfolio
PPTX
PPS
2 一定赢0917
PPTX
K-10714 ABHISHEK(TQM )
PPT
Img prod comp.030914
PDF
28/09/2016 - Communiqué de presse Orpéa
PPTX
Plan de investigación
PDF
E wthe littlleredhenandthperfectedeapplepie
PPT
Ximena computacion
LINKEDIN: Êtes vous prêt à utiliser tout son potentiel en 2017
Cevap Anahtarlari 1 35
 
Solution inc(speakers)
Peter VanPelt
Stress Testing Masterclass Johnk
ACOOK_portfolio
2 一定赢0917
K-10714 ABHISHEK(TQM )
Img prod comp.030914
28/09/2016 - Communiqué de presse Orpéa
Plan de investigación
E wthe littlleredhenandthperfectedeapplepie
Ad

Similar to Sql (20)

PDF
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
DOCX
DBMS LAB M.docx
PPTX
Database management system Lecture 6.pptx
PDF
Chapter – 6 SQL Lab Tutorial.pdf
PPSX
PPTX
More Complex SQL and Concurrency ControlModule 4.pptx
PPTX
SignalR & SQL Dependency
PPTX
SQL Optimizer vs Hive
PPTX
Introduction basic schema and SQL QUERIES
PPT
Advanced sql
PPTX
SQL Commands
PPTX
Advance SQL.pptx
PPTX
3-Chapter-Edit.pptx debre tabour university
PPTX
Introduction to SQL, SQL*Plus
PDF
CS3481_Database Management Laboratory .pdf
PDF
Application sql issues_and_tuning
PPTX
SQLite 3 chapter 4 BCA Notes Python NEP syllabus
PPTX
Advanced Database Systems - Presentation 3.pptx
PDF
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
PDF
Structure query language, database course
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
DBMS LAB M.docx
Database management system Lecture 6.pptx
Chapter – 6 SQL Lab Tutorial.pdf
More Complex SQL and Concurrency ControlModule 4.pptx
SignalR & SQL Dependency
SQL Optimizer vs Hive
Introduction basic schema and SQL QUERIES
Advanced sql
SQL Commands
Advance SQL.pptx
3-Chapter-Edit.pptx debre tabour university
Introduction to SQL, SQL*Plus
CS3481_Database Management Laboratory .pdf
Application sql issues_and_tuning
SQLite 3 chapter 4 BCA Notes Python NEP syllabus
Advanced Database Systems - Presentation 3.pptx
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Structure query language, database course

Recently uploaded (20)

PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
CyberSecurity Mobile and Wireless Devices
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PPTX
communication and presentation skills 01
PPTX
Current and future trends in Computer Vision.pptx
PPT
Total quality management ppt for engineering students
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PPTX
introduction to high performance computing
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Categorization of Factors Affecting Classification Algorithms Selection
CyberSecurity Mobile and Wireless Devices
August -2025_Top10 Read_Articles_ijait.pdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Management Information system : MIS-e-Business Systems.pptx
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
communication and presentation skills 01
Current and future trends in Computer Vision.pptx
Total quality management ppt for engineering students
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
introduction to high performance computing
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Visual Aids for Exploratory Data Analysis.pdf
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...

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