SlideShare a Scribd company logo
1 of 29
Basic Structure of SQL Queries
Queries on a Single Relation
• SQL allows us to use the keyword all to specify explicitly
that duplicates are not removed
select all dept_name
from instructor;
• Since duplicate retention is the default, we shall not use
all in our examples.
• To ensure the elimination of duplicates in the results of
queries, use distinct whenever it is necessary.
Basic Structure of SQL Queries
Queries on a Single Relation
• The select clause may also contain arithmetic
expressions involving the operators +, −, ∗, and / operating
on constants or attributes of tuples.
select ID, name, dept name, salary * 1.1
from instructor;
• returns a relation that is the same as the instructor
relation, except that the attribute salary is multiplied by
1.1
Basic Structure of SQL Queries
Queries on a Single Relation
• The where clause allows us to select only those rows in
the result relation of the from clause that satisfy a
specified predicate.
• Consider the query “Find the names of all instructors in
the Computer Science department who have salary
greater than $70,000.”
Basic Structure of SQL Queries
Queries on a Single Relation
select name
from instructor
where dept name = ’Comp. Sci.’ and salary > 70000;
• SQL allows the use of the logical connectives and, or, and
not in the whereclause.
Basic Structure of SQL Queries
Queries on a Single Relation
• The operands of the logical connectives can be
expressions involvingthe comparison operators <, <=, >,
>=, =, and <>.
• SQL allows us to use thecomparison operators to
compare strings and arithmetic expressions, as well as
special types, such as date types.
Basic Structure of SQL Queries
Queries on Multiple Relation
• Retrieve the names of all instructors along with their
department names and department building name.
• To answer this query each tuple in the intructor relation
must be matched with the tuple in the department
relation whose dept_name matches dept_name value of
the instructor tuple.
Basic Structure of SQL Queries
Queries on Multiple Relation
select name,instructor.dept_name,building
from instructor,department
where instructor.dept_name=department.dept_name;
Basic Structure of SQL Queries
Result of the query
Basic Structure of SQL Queries
Queries on Multiple Relation
• cartesian product
select instructor.ID, name, dept_name, salary,
teaches.ID, course_id, sec_id, semester,year
from instructor,teaches
• Each tuple in instructor is combined with every tuple in
teaches even those that refer to a different instructor.
Basic Structure of SQL Queries
Result of the query
Basic Structure of SQL Queries
Queries on Multiple Relation
• cartesian product
select instructor.ID, name, dept_name, salary,
teaches.ID, course_id, sec_id, semester,year
from instructor,teaches
where instructor.ID=teaches.ID;
• The result of the query is the instructors who have taught
some course.
Basic Structure of SQL Queries
Basic Structure of SQL Queries
Queries on Multiple Relation
cartesian product
• Find the instructor names and course identifiers for
instructors in the computer science department.
select instructor.ID, name, dept_name, salary,
teaches.ID, course_id, sec_id, semester,year
from instructor,teaches
where instructor.ID=teaches.ID and
instructor.dept_name='Comp.sci'
Basic Structure of SQL Queries
Result of the query
Instructor relation
teaches relation
Basic Structure of SQL Queries
Queries on Multiple Relation
The meaning of an SQL query can be understood as
1. Generate a catesian product of the relation listed in
the from clause.
2. Apply prdicates specified in the where clause on the
result of step 1.
3. For each tuple in the result of step 2 output the
attributes specified in the select clause.
Basic Structure of SQL Queries
Queries on Multiple Relation
Natural Join
• The natural join operation operates on two relations and
produces a relation as the result.
• It concatenates only those pairs of tuples with the same
value on those attributes that appear in the schemas of
both relations.
Basic Structure of SQL Queries
Queries on Multiple Relation
Natural Join
• Select all the attributes from the instructor and teaches
relation whose tuples in with the same value on the ID
attributes that appear same on both relations.
select instructor.ID, name, dept_name, salary,
course_id, sec_id, semester, year
from instructor natural join teaches;
Basic Structure of SQL Queries
Result
Basic Structure of SQL Queries
Queries on Multiple Relation
Natural Join
• Select name and course_id from the instructor and
teaches relation whose tuples in with the same value on
the ID attributes that appear same on both relations.
select name, course_id
from instructor natural join teaches;
Basic Structure of SQL Queries
Result
Basic Structure of SQL Queries
Queries on Multiple Relation
Natural Join
• A from clause in an SQL query can have multiple relations
combined using natural join
select A1,A2,...,An
from r1 natural join r2 natural join r3...natural join rm;
where P;
Basic Structure of SQL Queries
Queries on Multiple Relation
Natural Join
• List the names of instructors along with the titles of
courses that they teach.
select name,title
from instructor natural join teaches,course
where teaches.course_id=course.course_id;
Basic Structure of SQL Queries
Queries on Multiple Relation
Natural Join
• The natural join of instructor and teaches is computed
first, then a cartesian product of this result with course is
computed from which the where clause extracts only
those tuples where the course identifier from the join
result matches the course identifier from the course
relation.
Basic Structure of SQL Queries
Queries on Multiple Relation
Natural Join
• The following SQL query does not compute the same
result:
select name, title
from instructor natural join teaches natural
join course;
Basic Structure of SQL Queries
Queries on Multiple Relation
• To see why, the natural join of instructor and teaches
contains the attributes (ID, name, dept name, salary,
course id, sec id).
• while the course relation contains the attributes (course
id, title, dept name, credits).
• As a result, the natural join of these two would require
that the dept name attribute values from the two inputs
be the same.
Basic Structure of SQL Queries
Queries on Multiple Relation
• In addition to requiring that the course id values be the
same.
• This query would then omit all (instructor name, course
title) pairs where the instructorteaches a course in a
department other than the instructor’s own department.
Basic Structure of SQL Queries
Queries on Multiple Relation
select name, title
from (instructor natural join teaches) join course
using (course id);
• The operation join . . . using requires a list of attribute
names to be specified.
• Both inputs must have attributes with the specified
names.

More Related Content

What's hot

3 relational model
3 relational model3 relational model
3 relational modelUtkarsh De
 
Dependency Injection in Spring
Dependency Injection in SpringDependency Injection in Spring
Dependency Injection in SpringASG
 
OOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - LabOOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - LabVicter Paul
 
Logical Design and Conceptual Database Design
Logical Design and Conceptual Database DesignLogical Design and Conceptual Database Design
Logical Design and Conceptual Database DesignEr. Nawaraj Bhandari
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in javaHitesh Kumar
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7dplunkett
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)tameemyousaf
 
3.1 tuple relational_calculus
3.1 tuple relational_calculus3.1 tuple relational_calculus
3.1 tuple relational_calculusUtkarsh De
 
4. case study
4. case study4. case study
4. case studykhoahuy82
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standardUtkarsh De
 
Lec 1.6 Object Oriented Programming
Lec 1.6 Object Oriented ProgrammingLec 1.6 Object Oriented Programming
Lec 1.6 Object Oriented ProgrammingBadar Waseer
 
ER Diagrams Simplified
ER Diagrams SimplifiedER Diagrams Simplified
ER Diagrams SimplifiedPuneet Arora
 
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programmingHariz Mustafa
 

What's hot (17)

List classes
List classesList classes
List classes
 
3 relational model
3 relational model3 relational model
3 relational model
 
Dependency Injection in Spring
Dependency Injection in SpringDependency Injection in Spring
Dependency Injection in Spring
 
OOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - LabOOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - Lab
 
Logical Design and Conceptual Database Design
Logical Design and Conceptual Database DesignLogical Design and Conceptual Database Design
Logical Design and Conceptual Database Design
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
 
3.1 tuple relational_calculus
3.1 tuple relational_calculus3.1 tuple relational_calculus
3.1 tuple relational_calculus
 
Basic syntax
Basic syntaxBasic syntax
Basic syntax
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
4. case study
4. case study4. case study
4. case study
 
E3
E3E3
E3
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standard
 
Lec 1.6 Object Oriented Programming
Lec 1.6 Object Oriented ProgrammingLec 1.6 Object Oriented Programming
Lec 1.6 Object Oriented Programming
 
ER Diagrams Simplified
ER Diagrams SimplifiedER Diagrams Simplified
ER Diagrams Simplified
 
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programming
 

Similar to Introduction basic schema and SQL QUERIES

Data Base Management System - Basic Structure of SQL Queries
Data Base Management System - Basic Structure of SQL QueriesData Base Management System - Basic Structure of SQL Queries
Data Base Management System - Basic Structure of SQL Queriesjananisairam
 
Database Management System DBMS -SQL queries
Database Management System DBMS -SQL queriesDatabase Management System DBMS -SQL queries
Database Management System DBMS -SQL queriesSABITHARASSISTANTPRO
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasexabhaysonone0
 
Lecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptxLecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptxHanzlaNaveed1
 
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part IIIntro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part IIBlue Elephant Consulting
 
database management system
database management systemdatabase management system
database management systemNivetha Ganesan
 
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxAthosBeatus
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
 
Unit 4 Programming Assignment In this assignment, you will.docx
Unit 4 Programming Assignment In this assignment, you will.docxUnit 4 Programming Assignment In this assignment, you will.docx
Unit 4 Programming Assignment In this assignment, you will.docxlillie234567
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCOUM SAOKOSAL
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculusVaibhav Kathuria
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objectsmcollison
 

Similar to Introduction basic schema and SQL QUERIES (20)

Advance SQL.pptx
Advance SQL.pptxAdvance SQL.pptx
Advance SQL.pptx
 
Data Base Management System - Basic Structure of SQL Queries
Data Base Management System - Basic Structure of SQL QueriesData Base Management System - Basic Structure of SQL Queries
Data Base Management System - Basic Structure of SQL Queries
 
Database Management System DBMS -SQL queries
Database Management System DBMS -SQL queriesDatabase Management System DBMS -SQL queries
Database Management System DBMS -SQL queries
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
SQL3.pdf
SQL3.pdfSQL3.pdf
SQL3.pdf
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex
 
Lecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptxLecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptx
 
Sql
SqlSql
Sql
 
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part IIIntro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
 
database management system
database management systemdatabase management system
database management system
 
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
 
Data Retrival
Data RetrivalData Retrival
Data Retrival
 
SQL Optimizer vs Hive
SQL Optimizer vs Hive SQL Optimizer vs Hive
SQL Optimizer vs Hive
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
mis4200notes7_2.ppt
mis4200notes7_2.pptmis4200notes7_2.ppt
mis4200notes7_2.ppt
 
Unit 4 Programming Assignment In this assignment, you will.docx
Unit 4 Programming Assignment In this assignment, you will.docxUnit 4 Programming Assignment In this assignment, you will.docx
Unit 4 Programming Assignment In this assignment, you will.docx
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculus
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 

More from DHIVYADEVAKI

Computer Networks - DNS
Computer Networks - DNSComputer Networks - DNS
Computer Networks - DNSDHIVYADEVAKI
 
Error detection methods-computer networks
Error detection methods-computer networksError detection methods-computer networks
Error detection methods-computer networksDHIVYADEVAKI
 
Image compression in digital image processing
Image compression in digital image processingImage compression in digital image processing
Image compression in digital image processingDHIVYADEVAKI
 
Image segmentation in Digital Image Processing
Image segmentation in Digital Image ProcessingImage segmentation in Digital Image Processing
Image segmentation in Digital Image ProcessingDHIVYADEVAKI
 
Data preprocessing in Data Mining
Data preprocessing in Data MiningData preprocessing in Data Mining
Data preprocessing in Data MiningDHIVYADEVAKI
 
Apriori algorithm
Apriori algorithm Apriori algorithm
Apriori algorithm DHIVYADEVAKI
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemDHIVYADEVAKI
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDHIVYADEVAKI
 

More from DHIVYADEVAKI (9)

Computer Networks - DNS
Computer Networks - DNSComputer Networks - DNS
Computer Networks - DNS
 
Error detection methods-computer networks
Error detection methods-computer networksError detection methods-computer networks
Error detection methods-computer networks
 
Image compression in digital image processing
Image compression in digital image processingImage compression in digital image processing
Image compression in digital image processing
 
Image segmentation in Digital Image Processing
Image segmentation in Digital Image ProcessingImage segmentation in Digital Image Processing
Image segmentation in Digital Image Processing
 
R graphics
R graphicsR graphics
R graphics
 
Data preprocessing in Data Mining
Data preprocessing in Data MiningData preprocessing in Data Mining
Data preprocessing in Data Mining
 
Apriori algorithm
Apriori algorithm Apriori algorithm
Apriori algorithm
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed System
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 

Introduction basic schema and SQL QUERIES

  • 1. Basic Structure of SQL Queries Queries on a Single Relation • SQL allows us to use the keyword all to specify explicitly that duplicates are not removed select all dept_name from instructor; • Since duplicate retention is the default, we shall not use all in our examples. • To ensure the elimination of duplicates in the results of queries, use distinct whenever it is necessary.
  • 2. Basic Structure of SQL Queries Queries on a Single Relation • The select clause may also contain arithmetic expressions involving the operators +, −, ∗, and / operating on constants or attributes of tuples. select ID, name, dept name, salary * 1.1 from instructor; • returns a relation that is the same as the instructor relation, except that the attribute salary is multiplied by 1.1
  • 3. Basic Structure of SQL Queries Queries on a Single Relation • The where clause allows us to select only those rows in the result relation of the from clause that satisfy a specified predicate. • Consider the query “Find the names of all instructors in the Computer Science department who have salary greater than $70,000.”
  • 4. Basic Structure of SQL Queries Queries on a Single Relation select name from instructor where dept name = ’Comp. Sci.’ and salary > 70000; • SQL allows the use of the logical connectives and, or, and not in the whereclause.
  • 5. Basic Structure of SQL Queries Queries on a Single Relation • The operands of the logical connectives can be expressions involvingthe comparison operators <, <=, >, >=, =, and <>. • SQL allows us to use thecomparison operators to compare strings and arithmetic expressions, as well as special types, such as date types.
  • 6. Basic Structure of SQL Queries Queries on Multiple Relation • Retrieve the names of all instructors along with their department names and department building name. • To answer this query each tuple in the intructor relation must be matched with the tuple in the department relation whose dept_name matches dept_name value of the instructor tuple.
  • 7. Basic Structure of SQL Queries Queries on Multiple Relation select name,instructor.dept_name,building from instructor,department where instructor.dept_name=department.dept_name;
  • 8. Basic Structure of SQL Queries Result of the query
  • 9. Basic Structure of SQL Queries Queries on Multiple Relation • cartesian product select instructor.ID, name, dept_name, salary, teaches.ID, course_id, sec_id, semester,year from instructor,teaches • Each tuple in instructor is combined with every tuple in teaches even those that refer to a different instructor.
  • 10. Basic Structure of SQL Queries Result of the query
  • 11. Basic Structure of SQL Queries Queries on Multiple Relation • cartesian product select instructor.ID, name, dept_name, salary, teaches.ID, course_id, sec_id, semester,year from instructor,teaches where instructor.ID=teaches.ID; • The result of the query is the instructors who have taught some course.
  • 12. Basic Structure of SQL Queries
  • 13. Basic Structure of SQL Queries Queries on Multiple Relation cartesian product • Find the instructor names and course identifiers for instructors in the computer science department. select instructor.ID, name, dept_name, salary, teaches.ID, course_id, sec_id, semester,year from instructor,teaches where instructor.ID=teaches.ID and instructor.dept_name='Comp.sci'
  • 14. Basic Structure of SQL Queries Result of the query
  • 17. Basic Structure of SQL Queries Queries on Multiple Relation The meaning of an SQL query can be understood as 1. Generate a catesian product of the relation listed in the from clause. 2. Apply prdicates specified in the where clause on the result of step 1. 3. For each tuple in the result of step 2 output the attributes specified in the select clause.
  • 18. Basic Structure of SQL Queries Queries on Multiple Relation Natural Join • The natural join operation operates on two relations and produces a relation as the result. • It concatenates only those pairs of tuples with the same value on those attributes that appear in the schemas of both relations.
  • 19. Basic Structure of SQL Queries Queries on Multiple Relation Natural Join • Select all the attributes from the instructor and teaches relation whose tuples in with the same value on the ID attributes that appear same on both relations. select instructor.ID, name, dept_name, salary, course_id, sec_id, semester, year from instructor natural join teaches;
  • 20. Basic Structure of SQL Queries Result
  • 21. Basic Structure of SQL Queries Queries on Multiple Relation Natural Join • Select name and course_id from the instructor and teaches relation whose tuples in with the same value on the ID attributes that appear same on both relations. select name, course_id from instructor natural join teaches;
  • 22. Basic Structure of SQL Queries Result
  • 23. Basic Structure of SQL Queries Queries on Multiple Relation Natural Join • A from clause in an SQL query can have multiple relations combined using natural join select A1,A2,...,An from r1 natural join r2 natural join r3...natural join rm; where P;
  • 24. Basic Structure of SQL Queries Queries on Multiple Relation Natural Join • List the names of instructors along with the titles of courses that they teach. select name,title from instructor natural join teaches,course where teaches.course_id=course.course_id;
  • 25. Basic Structure of SQL Queries Queries on Multiple Relation Natural Join • The natural join of instructor and teaches is computed first, then a cartesian product of this result with course is computed from which the where clause extracts only those tuples where the course identifier from the join result matches the course identifier from the course relation.
  • 26. Basic Structure of SQL Queries Queries on Multiple Relation Natural Join • The following SQL query does not compute the same result: select name, title from instructor natural join teaches natural join course;
  • 27. Basic Structure of SQL Queries Queries on Multiple Relation • To see why, the natural join of instructor and teaches contains the attributes (ID, name, dept name, salary, course id, sec id). • while the course relation contains the attributes (course id, title, dept name, credits). • As a result, the natural join of these two would require that the dept name attribute values from the two inputs be the same.
  • 28. Basic Structure of SQL Queries Queries on Multiple Relation • In addition to requiring that the course id values be the same. • This query would then omit all (instructor name, course title) pairs where the instructorteaches a course in a department other than the instructor’s own department.
  • 29. Basic Structure of SQL Queries Queries on Multiple Relation select name, title from (instructor natural join teaches) join course using (course id); • The operation join . . . using requires a list of attribute names to be specified. • Both inputs must have attributes with the specified names.