Help joining 2 tables

Hi All

I am trying to cross join 2 tables in a PHP while loop and for the life of me can’t get it to work… I have never been very good at this sort of code.

I am hoping that someone can pretty please help me with this SQL.

I have 2 tables… product_colour_sizes and product_sizes.

I want to select everything that is in product_colour_sizes where the product_colour_sizes sizeID is the same as the product_sizes uniqueID and then order the result by the productSizeTableHeadingPositionID in product_sizes.

I think that will give me the result I am looking for.

The code I have come up with so far is this…

$sql = “SELECT * FROM product_colour_sizes WHERE product_colour_sizes.sizeID = product_sizes.uniqueID CROSS JOIN product_sizes ORDER BY product_sizes.productSizeTableHeadingPositionID ASC”;

Any help would be AWESOME!


What database system are you using? Most (if not all) database systems put the JOIN before the WHERE.

It is a mySQL database using phpMyAdmin.

If you stick this SQL string into phpMyAdmin, it’ll abort on you at the word CROSS.

Since what you’re trying to define with your WHERE is actually a join condition, lets rewrite it to actually be the join condition, and redefine your join as an INNER join:

FROM product_colour_sizes 
INNER JOIN product_sizes 
ON product_colour_sizes.sizeID = product_sizes.uniqueID 
ORDER BY product_sizes.productSizeTableHeadingPositionID ASC

That did the trick… thank you so very much for your help!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.