Skip to Content
SQL and Relational Theory
book

SQL and Relational Theory

by C.J. Date
January 2009
Intermediate to advanced
426 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from SQL and Relational Theory

Chapter 7. SQL and Relational Algebra II: Additional Operators

AS I’VE SAID SEVERAL TIMES ALREADY, AN OPERATOR OF THE RELATIONAL ALGEBRA IS AN OPERATOR THAT TAKES ONE OR MORE RELATIONS AS INPUT AND PRODUCES ANOTHER RELATION AS OUTPUT. As I observed in Chapter 1, however, any number of operators can be defined that conform to this simple characterization. Chapter 6 described the original operators (join, project, etc.); the present chapter describes some of the many additional operators that have been defined since the relational model was first invented. It also considers how those operators can best be realized in SQL.

Semijoin and Semidifference

Join is one of the most familiar of all of the relational operators. In practice, however, it often turns out that many queries that require join at all really require an extended form of that operator called semijoin (you might not have heard of semijoin before, but in fact it’s quite important).

Definition: The semijoin of relations r1 and r2 (in that order), r1 MATCHING r2, is equivalent to (r1 JOIN r2){A,B,…,C}, where A, B, …, C are all of the attributes of r1.

In other words, r1 MATCHING r2 is the join of r1 and r2, projected back on the attributes of r1. Here’s an example (“Get suppliers who currently supply at least one part”):

S MATCHING SP                  |    SELECT S.* FROM S
                               |    WHERE  SNO IN
                               |         ( SELECT SNO FROM SP )

The result heading is the same as that of S. Note that the expressions r1 MATCHING r2 and r2 MATCHING r1 aren’t equivalent, in general. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

SQL and Relational Theory, 2nd Edition

SQL and Relational Theory, 2nd Edition

C.J. Date

Publisher Resources

ISBN: 9780596155865Errata Page