SlideShare a Scribd company logo
1 of 12
Basic Structure of SQL Queries
Mrs.R.SABITHA .,M.Sc.,M.Phil.,
Assistant Professor,
Department of Computer Science(SF)
V.V.Vanniaperumal College for Women,
Virudhunagar.
 Overview of the SQL Query Language
 Data Definition
 Basic Query Structure
 Additional Basic Operations
 Set Operations
 Null Values
 Aggregate Functions
 Nested Sub queries
Overview of the SQL Query
Language
• SQL is a language to operate databases; it includes
Database Creation, Database Deletion, Fetching Data Rows,
Modifying & Deleting Data rows, etc.
• SQL stands for Structured Query Language which is a
computer language for storing, manipulating and retrieving
data stored in a relational database.
SQL Basic Commands
DDL (Data Definition Languages)
1. Create - Creates a new table, a view of a table, or other
object in the database.
2. Alter - Modifies an existing database object, such as a
table.
3. Drop - Deletes an entire table, a view of a table or
other objects in the database.
SQL Basic Commands
DML - Data Manipulation Language
1. SELECT - Retrieves certain records from one or more
tables.
2. Update – Modify records
3 .Delete – Delete Records
Basic Query Structure
 A typical SQL query has the form:
select A1, A2, ..., An
from r1, r2, ..., rm
where P
 Ai represents an attribute
 Ri represents a relation
 P is a predicate.
 The result of an SQL query is a relation.
Select Clause
The select clause lists the attributes desired in the result of a query
corresponds to the projection operation of the relational algebra
Example: find the names of all instructors:
select name from instructor
NOTE: SQL names are case insensitive (i.e., you may use upper- or lower-case
letters.)
E.g., Name ≡ NAME ≡ name
Select Clause
SQL allows duplicates in relations as well as in query results.
To force the elimination of duplicates, insert the keyword distinct
after select.
Find the department names of all instructors, and remove duplicates
select distinct dept_name
from instructor
The keyword all specifies that duplicates should not be removed.
select all dept_name
from instructor
The from Clause
 The from clause lists the relations involved in the query
 Corresponds to the Cartesian product operation of the relational algebra.
 Find the Cartesian product instructor X teaches
select X
from instructor, teaches
 generates every possible instructor – teaches pair, with all attributes from
both relations.
 For common attributes (e.g., ID), the attributes in the resulting table are
renamed using the relation name (e.g., instructor.ID)
The where Clause
 The where clause specifies conditions that the result must satisfy
 Corresponds to the selection predicate of the relational algebra.
 To find all instructors in Comp. Sci. dept
select name
from instructor
where dept_name = ‘Comp. Sci.'
 To find all instructors in Comp. Sci. dept with salary > 80000
select name
from instructor
where dept_name = ‘Comp. Sci.' and salary > 80000
Examples
 Find the names of all instructors who have taught some course and the
course_id
 select name, course_id
from instructor , teaches
where instructor.ID = teaches.ID
 Find the names of all instructors in the Art department who have taught
some course and the course_id
 select name, course_id
from instructor , teaches
where instructor.ID = teaches.ID and instructor. dept_name = ‘Art’
ThankYou

More Related Content

Similar to Data Base Management System - Basic Structure of SQL Queries

Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .
MayankSinghRawat6
 
Ch-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced databaseCh-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced database
tasheebedane
 

Similar to Data Base Management System - Basic Structure of SQL Queries (20)

Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
lect 2.pptx
lect 2.pptxlect 2.pptx
lect 2.pptx
 
lovely
lovelylovely
lovely
 
mysql.ppt
mysql.pptmysql.ppt
mysql.ppt
 
Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .
 
Introduction to dbms
Introduction to dbmsIntroduction to dbms
Introduction to dbms
 
sql-commands.pdf
sql-commands.pdfsql-commands.pdf
sql-commands.pdf
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql commands
Sql commandsSql commands
Sql commands
 
Module02
Module02Module02
Module02
 
SQL Query
SQL QuerySQL Query
SQL Query
 
chapter-14-sql-commands.pdf
chapter-14-sql-commands.pdfchapter-14-sql-commands.pdf
chapter-14-sql-commands.pdf
 
Relational data model
Relational data modelRelational data model
Relational data model
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Ch-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced databaseCh-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced database
 
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standard
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 

Data Base Management System - Basic Structure of SQL Queries

  • 1. Basic Structure of SQL Queries Mrs.R.SABITHA .,M.Sc.,M.Phil., Assistant Professor, Department of Computer Science(SF) V.V.Vanniaperumal College for Women, Virudhunagar.
  • 2.  Overview of the SQL Query Language  Data Definition  Basic Query Structure  Additional Basic Operations  Set Operations  Null Values  Aggregate Functions  Nested Sub queries
  • 3. Overview of the SQL Query Language • SQL is a language to operate databases; it includes Database Creation, Database Deletion, Fetching Data Rows, Modifying & Deleting Data rows, etc. • SQL stands for Structured Query Language which is a computer language for storing, manipulating and retrieving data stored in a relational database.
  • 4. SQL Basic Commands DDL (Data Definition Languages) 1. Create - Creates a new table, a view of a table, or other object in the database. 2. Alter - Modifies an existing database object, such as a table. 3. Drop - Deletes an entire table, a view of a table or other objects in the database.
  • 5. SQL Basic Commands DML - Data Manipulation Language 1. SELECT - Retrieves certain records from one or more tables. 2. Update – Modify records 3 .Delete – Delete Records
  • 6. Basic Query Structure  A typical SQL query has the form: select A1, A2, ..., An from r1, r2, ..., rm where P  Ai represents an attribute  Ri represents a relation  P is a predicate.  The result of an SQL query is a relation.
  • 7. Select Clause The select clause lists the attributes desired in the result of a query corresponds to the projection operation of the relational algebra Example: find the names of all instructors: select name from instructor NOTE: SQL names are case insensitive (i.e., you may use upper- or lower-case letters.) E.g., Name ≡ NAME ≡ name
  • 8. Select Clause SQL allows duplicates in relations as well as in query results. To force the elimination of duplicates, insert the keyword distinct after select. Find the department names of all instructors, and remove duplicates select distinct dept_name from instructor The keyword all specifies that duplicates should not be removed. select all dept_name from instructor
  • 9. The from Clause  The from clause lists the relations involved in the query  Corresponds to the Cartesian product operation of the relational algebra.  Find the Cartesian product instructor X teaches select X from instructor, teaches  generates every possible instructor – teaches pair, with all attributes from both relations.  For common attributes (e.g., ID), the attributes in the resulting table are renamed using the relation name (e.g., instructor.ID)
  • 10. The where Clause  The where clause specifies conditions that the result must satisfy  Corresponds to the selection predicate of the relational algebra.  To find all instructors in Comp. Sci. dept select name from instructor where dept_name = ‘Comp. Sci.'  To find all instructors in Comp. Sci. dept with salary > 80000 select name from instructor where dept_name = ‘Comp. Sci.' and salary > 80000
  • 11. Examples  Find the names of all instructors who have taught some course and the course_id  select name, course_id from instructor , teaches where instructor.ID = teaches.ID  Find the names of all instructors in the Art department who have taught some course and the course_id  select name, course_id from instructor , teaches where instructor.ID = teaches.ID and instructor. dept_name = ‘Art’