The final type of logical relationship that you might need to display in a form is the many-to-many relationship, which is represented by three or more tables in the database.
In the vast majority of cases, you can treat many-to-many relationships as though they were one-to-many relationships. For example, Figure 14-7 shows a many-to-many relationship between Customers and Products, with the Orders and Order Details tables acting as the junction tables.
Figure 14-7. Customers and Products have a many-to-many relationship.
It's reasonable to display all the products a customer has ordered (in which case, you would treat the Customers table as the one side of the relationship) or all the customers who have ordered a product (in which case, the Products table is the one side). You can use the same presentation techniques as for any other one-to-many form. You need only address where to include data from the junction tables and how to handle duplicates on the many side.
Most junction tables contain only the primary keys from each side of the many-to-many relationship. As we saw in Chapter 3 and as shown in Figure 14-7, however, the relationship itself sometimes has attributes that are
In our example, if the form is to display the products for each customer (the Customers table being the one side), the order date—which is a field in the Orders table—is clearly part of the product information, not the customer information. "Customer X bought product Y on the 15th and product Z on the 18th..." The order date would be part of the customer information if the display were the other way around, with Products being the one side: "Product X was purchased by customer Y on the 15th and customer Z on the 18th...," as in this case the Customers table is treated as the many side.
{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}It's quite likely that there will be duplicates, or at least partial duplicates, on the many side of the display. You must decide whether to display each item individually or to show summary information. For example, if you are listing the customers who purchased each product, you might choose to list the customer once for each product purchased; or you might just list each customer a single time, and show the total number of times the customer ordered the product and the total (and perhaps the average) quantity purchased.
You need to be careful here to avoid listing complete duplicates. It's of no use whatever to simply list a customer
Although
One relatively simple solution here is to treat the relationships as hierarchies and use
If you're
A product manager looking at other products bought by a customer might prefer a list of products purchased by all customers who bought the primary product to be organized according to the percentage of overlap—for example, all the customers who bought a widget bought a gizmo, but only 10 percent of these customers bought a doohickey. You can, of course, provide some of this summary information on the main form, but since the calculation is
The two techniques for displaying all the data in a many-to-many relationship are not