SlideShare una empresa de Scribd logo
1 de 28
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Union and Intersection
Zabeeb anwar
zabeebanwar@gmail.com
www.fb.com/zabeebanwar
twitter.com/zabeebanwar
in/linkedin.com/in/zabeeb
9895599689
union
AUB
- AUB(OR) means the union of sets A and B
contains all of the elements of both A and B.
Intersection
AÇB(AND) means the intersection of sets A
and B. This contains all of the elements which
are in both A and B.
Union and Intersection with empty
Union and Intersection in Psql
Union
- A hot startup is holding a special event and
wants to send out invites for my marriage()
to some of my best clients and also to some
VIPs.
- Some of the VIPs are actually very supportive
of the site and are clients too.
- What query will provide the complete set of
people to invite avoiding duplicate records?
- Here is our data.
Union
• create database hotstartup;
• create table clients(name varchar);
insert into clients values(‘Sharan');
insert into clients values(‘Vineesh');
insert into clients values(‘Bala');
insert into clients values(‘Sheethal');
• create table vips(name varchar);
insert into vips values(‘Reshmi');
insert into vips values(‘Sheethal');
insert into vips values(‘Anupa');
insert into vips values(‘Ashwathy');
Union
• hotstartup=# select * from clients union select *
from vips;
name
----------------
Sharan
Vineesh
Bala
Sheethal
Reshmi
Anupa
Ashwathy
(7 rows)
Union All
• hotstartup=# select * from clients union all select * from vips;
name
----------------
Sharan
Vineesh
Bala
Sheethal
Reshmi
sheethal
Anupa
Ashwathy
(8 rows)
Intersect
• if I want to get the list of people who are both
clients and VIP we can use INTERSECT.
• hotstartup=# select * from
clients intersect select * from vips;
name
----------------
Sheethal
(1 row)
Intersect All
• Let's insert a Sheethal(duplicate name) into VIP’s.
name
----------------
Sharan
Vineesh
Bala
Sheethal
Sheethal
(4 rows)
-select * from client intersect all select * from vips;
Intersect All
name
----------------
sheethal
sheethal
(2 rows)
- Sheethal appears in both tables twice so we
find two matching pairs for her and hence two
rows appears in the results.
Except
• I want everyone on the clients list EXCEPT those on
the VIP list.
• select * from clients except select * from vips;
name
----------------
Sharan
Vineesh
Bala
Except All
• Let's insert a Sheethal(duplicate name) into clients.
name
----------------
Sharan
Vineesh
Bala
Sheethal
Sheethal
(4 rows)
-select * from clients except all select * from vips;
Except All
name
----------------
Sharan
Vineesh
Bala
Sheethal
(4 rows)
Where Clause
• select * from Clients_Year;
name | Birth year
------------------+------
Sharan | 1976
Vineesh | 1977
Bala | 1978
Ashwathy | 1983
Reshmi | 199 3
sheethal | 1996
Anupa | 1997
Where Clause
• select * from clients_year where year
between 1970 and 1979 union select * from
ceos where year=1977;
name | Birth year
------------------+------
Sharan | 1976
Vineesh | 1977
Bala | 1978
Do not
• select * from clients where year between
1970 and 1979 union select name from clients
where year=1977;
ERROR: each UNION query must have the
same number of columns
Union and intersection in Python
Example
>>>engineers = Set(['John', 'Jane', 'Jack',
'Janice'])
>>>programmers = Set(['Jack', 'Sam', 'Susan',
'Janice'])
>>>managers = Set(['Jane', 'Jack', 'Susan',
'Zack'])
Union
>>>employees = engineers | programmers |
managers
>>>print “employees”
Set(['Jane', 'Janice', 'John’,
'Jack’,’susan’,’Zack’,’sam’])
Intersection
>>>engineers = Set(['John', 'Jane', 'Jack',
'Janice'])
>>>managers = Set(['Jane', 'Jack', 'Susan',
'Zack'])
>>>engineering_management = engineers &
managers
>>>print “engineering_management”
Set(['Jane', 'Jack’])
Questions
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us

Más contenido relacionado

Más de baabtra.com - No. 1 supplier of quality freshers

Más de baabtra.com - No. 1 supplier of quality freshers (20)

Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 
Cell phone jammer
Cell phone jammerCell phone jammer
Cell phone jammer
 
Apple iwatches
Apple iwatchesApple iwatches
Apple iwatches
 
Driverless car
Driverless carDriverless car
Driverless car
 
Brain computer interface(neethu,bincy,sanooja)
Brain computer interface(neethu,bincy,sanooja)Brain computer interface(neethu,bincy,sanooja)
Brain computer interface(neethu,bincy,sanooja)
 

Último

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 

Último (20)

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. Union and Intersection Zabeeb anwar zabeebanwar@gmail.com www.fb.com/zabeebanwar twitter.com/zabeebanwar in/linkedin.com/in/zabeeb 9895599689
  • 4. union AUB - AUB(OR) means the union of sets A and B contains all of the elements of both A and B.
  • 5. Intersection AÇB(AND) means the intersection of sets A and B. This contains all of the elements which are in both A and B.
  • 8. Union - A hot startup is holding a special event and wants to send out invites for my marriage() to some of my best clients and also to some VIPs. - Some of the VIPs are actually very supportive of the site and are clients too. - What query will provide the complete set of people to invite avoiding duplicate records? - Here is our data.
  • 9. Union • create database hotstartup; • create table clients(name varchar); insert into clients values(‘Sharan'); insert into clients values(‘Vineesh'); insert into clients values(‘Bala'); insert into clients values(‘Sheethal'); • create table vips(name varchar); insert into vips values(‘Reshmi'); insert into vips values(‘Sheethal'); insert into vips values(‘Anupa'); insert into vips values(‘Ashwathy');
  • 10. Union • hotstartup=# select * from clients union select * from vips; name ---------------- Sharan Vineesh Bala Sheethal Reshmi Anupa Ashwathy (7 rows)
  • 11. Union All • hotstartup=# select * from clients union all select * from vips; name ---------------- Sharan Vineesh Bala Sheethal Reshmi sheethal Anupa Ashwathy (8 rows)
  • 12. Intersect • if I want to get the list of people who are both clients and VIP we can use INTERSECT. • hotstartup=# select * from clients intersect select * from vips; name ---------------- Sheethal (1 row)
  • 13. Intersect All • Let's insert a Sheethal(duplicate name) into VIP’s. name ---------------- Sharan Vineesh Bala Sheethal Sheethal (4 rows) -select * from client intersect all select * from vips;
  • 14. Intersect All name ---------------- sheethal sheethal (2 rows) - Sheethal appears in both tables twice so we find two matching pairs for her and hence two rows appears in the results.
  • 15. Except • I want everyone on the clients list EXCEPT those on the VIP list. • select * from clients except select * from vips; name ---------------- Sharan Vineesh Bala
  • 16. Except All • Let's insert a Sheethal(duplicate name) into clients. name ---------------- Sharan Vineesh Bala Sheethal Sheethal (4 rows) -select * from clients except all select * from vips;
  • 18. Where Clause • select * from Clients_Year; name | Birth year ------------------+------ Sharan | 1976 Vineesh | 1977 Bala | 1978 Ashwathy | 1983 Reshmi | 199 3 sheethal | 1996 Anupa | 1997
  • 19. Where Clause • select * from clients_year where year between 1970 and 1979 union select * from ceos where year=1977; name | Birth year ------------------+------ Sharan | 1976 Vineesh | 1977 Bala | 1978
  • 20. Do not • select * from clients where year between 1970 and 1979 union select name from clients where year=1977; ERROR: each UNION query must have the same number of columns
  • 22. Example >>>engineers = Set(['John', 'Jane', 'Jack', 'Janice']) >>>programmers = Set(['Jack', 'Sam', 'Susan', 'Janice']) >>>managers = Set(['Jane', 'Jack', 'Susan', 'Zack'])
  • 23. Union >>>employees = engineers | programmers | managers >>>print “employees” Set(['Jane', 'Janice', 'John’, 'Jack’,’susan’,’Zack’,’sam’])
  • 24. Intersection >>>engineers = Set(['John', 'Jane', 'Jack', 'Janice']) >>>managers = Set(['Jane', 'Jack', 'Susan', 'Zack']) >>>engineering_management = engineers & managers >>>print “engineering_management” Set(['Jane', 'Jack’])
  • 26.
  • 27. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com