Đang chuẩn bị liên kết để tải về tài liệu:
Beginning Databases with Postgre SQL phần 3
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
hay hệ thống UNIX như Linux, FreeBSD, AIX, Solaris, HP-UX, hoặc Mac OS X-nó không phải là khó khăn để biên dịch PostgreSQL từ mã nguồn. Chúng tôi cũng sẽ làm thế nào để cài đặt và thiết lập PostgreSQL trên nền tảng Windows, sử dụng trình cài đặt Windows được giới thiệu trong phiên bản PostgreSQL 8,0. | CHAPTER 4 ACCESSING YOUR DATA 109 we need to use an extra table the item table to get at the item description. The rest of the query however is pretty much as before bpsimple SELECT customer.fname customer.lname orderinfo.date_placed bpsimple- item.description orderline.quantity bpsimple- FROM customer orderinfo orderline item bpsimple- WHERE bpsimple- customer.customer_id orderinfo.customer_id AND bpsimple- orderinfo.orderinfo_id orderline.orderinfo_id AND bpsimple- orderline.item_id item.item_id AND bpsimple- customer.fname Ann AND bpsimple- customer.lname Stones fname lname date_placed description quantity ------- -------- ------------- -------------- ---------- Ann Stones 2004-06-23 Wood Puzzle 1 Ann Stones 2004-06-23 Tissues 2 Ann Stones 2004-06-23 Fan Large 2 Ann Stones 2004-06-23 Carrier Bag 1 Ann Stones 2004-07-21 Wood Puzzle 1 Ann Stones 2004-07-21 Linux CD 1 6 rows bpsimple How It Works Once you have seen how three-table joins work it s not difficult to extend the idea to more tables. We added the item description to the list of columns to be shown added the item table to the list of tables to select from and added the information about how to relate the item table to the tables we already had orderline.item_id item.item_id. You will notice that Wood Puzzle is listed twice since it was purchased on two different occasions. In this SELECT we have displayed at least one column from each of the tables we used in our join. There is actually no need to do this. If we had just wanted the customer name and item description we could have simply chosen not to retrieve the columns we didn t need. A version retrieving fewer columns is just as valid and may be marginally more efficient than our earlier attempt SELECT customer.fname customer.lname item.description FROM customer orderinfo orderline item WHERE customer.customer_id orderinfo.customer_id AND orderinfo.orderinfo_id orderline.orderinfo_id AND orderline.item_id item.item_id AND customer.fname Ann AND .