TAILIEUCHUNG - beginning microsofl sql server 2008 programming phần 3

Chúng tôi có một kết quả thiết lập từ những gì đã có hai. SQL Server có chạy cả hai truy vấn và cơ bản xếp chồng lên nhau trên đầu trang của người khác để tạo ra một tập hợp kết quả kết hợp. Một lần nữa, nhận thấy rằng các tiêu đề cho các cột trở lại đến từ các | Chapter 4 JOINS JOIN sc ON UNION SELECT FirstName LastName AS Name EmailAddress FROM pp JOIN pe ON JOIN pv ON This gets back just one result set Name EmailAddress A. Scott Wright Aaron Adams Aaron Allen ascott0@ aaron48@ aaron55@ Zachary Wilson Zainal Arifin Zheng Mu zachary36@ zainal0@ zheng0@ 10274 row s affected How It Works We have our one result set from what would have been two. SQL Server has run both queries and essentially stacked the results one on top of the other to create one combined result set. Again notice that the headings for the returned columns all came from the SELECT list of the first of the queries. Moving on to a second example let s take a look at how a UNION deals with duplicate rows it s actually just the inverse of a normal query in that it assumes you want to throw out duplicates. In your previous queries the assumption was that you wanted to keep everything unless you used the DISTINCT keyword. This demo has no real-world potential but it s quick and easy to run and see how things work. In this case we are creating two tables from which we will select. We ll then insert three rows into each table with one row being identical between the two tables. If our query is performing an ALL then every row six of them will show up. If the query is performing a DISTINCT then it will only return five rows tossing out one duplicate CREATE TABLE UnionTest1 idcol int IDENTITY col2 char 3 109 Chapter 4 JOINS CREATE TABLE UnionTest2 idcol int IDENTITY col4 char 3 INSERT INTO UnionTest1 VALUES AAA INSERT INTO UnionTestl VALUES BBB INSERT INTO UnionTestl VALUES CCC INSERT INTO UnionTest2 VALUES CCC INSERT INTO UnionTest2 VALUES DDD INSERT INTO .

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.