TAILIEUCHUNG - Joe Celko s SQL for Smarties - Advanced SQL Programming P38

Joe Celko s SQL for Smarties - Advanced SQL Programming P38. 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 audience. | 342 CHAPTER 17 THE SELECT STATEMENT However I could write SELECT sup_id sup_name SELECT COUNT FROM Orders WHERE FROM Suppliers instead of writing SELECT sup_id sup_name COUNT FROM Suppliers LEFT OUTER JOIN Orders ON GROUP BY sup_id sup_name NULLs and OUTER JOINs The nulls generated by the outer join can occur in columns derived from source table columns that have been declared to be not NULL. Even if you tried to avoid all the problems with NULLs by making every column in every table of your database schema NOT null they could still occur in OUTER JOIN and OLAP function results. However a table can have nulls and still be used in an outer join. Consider different JOINs on the following two tables which have NULLs in the common column T1 T2 a x b x 1 - r - 7 - r 2 v 8 s 3 NULL 9 NULL A natural INNER JOIN on column x can only match those values that are equal to each other. But nulls do not match to anything even to other NULLs. Thus there is one row in the result on the value r in column x in both tables. O OUTER JOINs 343 T1 INNER JOIN T2 ON a b 1 r 7 r Now do a left outer join on the tables which will preserve table T1 and you get T1 LEFT OUTER JOIN T2 ON a b 1 r 7 r 2 v NULL NULL 3 NULL NULL NULL Again there are no surprises. The original INNER JOIN row is still in the results. The other two rows of T1 that were not in the equi-JOlN do show up in the results and the columns derived from table T2 are filled with NULLs. The right OUTER join would behave the same way. The problems start with the FULL OUTER JOIN which looks like this T1 FULL OUTER JOIN T2 ON a b 1 r 7 r 2 v NULL NULL 3 NULL NULL NULL NULL NULL 8 s NULL NULL 9 NULL The way this result is constructed is worth explaining in detail. First do an INNER JOIN on T1 and T2 using the ON clause condition and put those rows if any in the results. Then all rows in T1 that could not

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.