Joe Celko s SQL for Smarties - Advanced SQL Programming P64

Joe Celko s SQL for Smarties - Advanced SQL Programming P64. In the SQL database community, Joe Celko is a well-known columnist and purveyor of valuable insights. In Joe Celko's SQL for Smarties: Advanced SQL Programming, he picks up where basic SQL training and experience leaves many database professionals and offers tips, techniques, and explanations that help readers extend their capabilities to top-tier SQL programming. Although Celko denies that the book is about database theory, he nevertheless alludes to theory often to buttress his practical points. This title is not for novices, as the author points out. Instead, its intended. | 602 CHAPTER 26 SET OPERATIONS CREATE TABLE B i INTEGER NOT NULL INSERT INTO B VALUES 2 2 3 3 The union and intersect operations have regular behavior in that A UNION B SELECT DISTINCT A UNION ALL B 1 2 3 and A INTERSECT B SELECT DISTINCT A INTERSECT ALL B 2 However A EXCEPT B SELECT DISTINCT A EXCEPT ALL B Or more literally 1 1 2 for the tables given in the example. Likewise we have B EXCEPT A SELECT DISTINCT B EXCEPT ALL A 3 by a coincidence of the particular values used in these tables. Equality and Proper Subsets At one point when SQL was still in the laboratory at IBM there was a contains operator that would tell you if one table was a subset of another. It disappeared in later versions of the language and no vendor picked it up. Set equality was never part of SQL as an operator so you would have to have used the two expressions A contains b and B CONTAINS a to find out. Today you can use the methods shown in the section on Relational Division to determine containment or equality. However Itzik Ben-Gan came up with a novel approach for finding containment and equality that is worth a mention. SELECT SUM DISTINCT match_col FROM SELECT CASE WHEN IN SELECT FROM S2 THEN 1 ELSE -1 END FROM Sl AS X match_col HAVING SUM DISTINCT match_col n Equality and Proper Subsets 603 You can set n to 1 0 or -1 for each particular test. When I find a matching row in S1 I get a 1 when I find a mismatched row in S1 get a -1 and they sum together to give me a zero. Therefore S1 is a proper subset of S2. If they sum to 1 then they are equal. If they sum to -1 they are .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
204    97    3    15-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.