Prev | Current Page 269 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

The sample data of our
database contains 14 possible attribute values and 101 products. The cross join operation that associates all attribute
values to all products generates 1,414 (which is 14 multiplied by 101) records into the product_attribute
table.
Note that the use of SELECT to create the cross join is not standard SQL; if you want to implement such an operation
with other database servers, you may need to use different syntax. The ???official??? syntax to implement cross
joins specifies the use of the CROSS JOIN syntax.
There are a few alternative methods to using the cross join to populate the product_attribute table with the
necessary data. One method that we think is worth discussing here is to use UNION, because it??™s quite frequently
used in such situations. UNION sums up the results of multiple SELECT statements into a single result set. For
example, if you use UNION for two queries that return five records each, you get a result set of ten records. Of
course, for UNION to work, all the queries involved must return the same number of columns of compatible data
types.We won??™t go into more details about UNION, but if you??™re curious to see the UNION-based implementation of
the cross join, here it is. It necessitates more keystrokes, but the query offers you more flexibility; for example, using
UNION, you could add only certain attribute values to your products.


Pages:
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281