webent Posted June 28, 2008 Share Posted June 28, 2008 Can someone please help me with the syntax of how to join 2 different databases with 2 different tables? Also, the table name of second query is dynamic and thus, a variable. The common shared field name of both tables is the SKU. Here's my code for the two queries,... $result = mysql_query("SELECT SKU FROM domain_supplier.featured_products WHERE featured_products_id = '1'", $b_link); while ($row = mysql_fetch_assoc($result)) { $SKU = $row['SKU']; $sub_result = mysql_query("SELECT PRODUCT_IMAGE, MSRP, PRODUCT_NAME FROM domain_supplier.$single_product_line ORDER BY RAND() WHERE SKU = '$row[sKU]'", $a_link); while ($sub_row = mysql_fetch_assoc($sub_result)) { $PRODUCT_IMAGE = $sub_row['PRODUCT_IMAGE']; $MSRP = $sub_row['MSRP']; $PRODUCT_NAME = $sub_row['PRODUCT_NAME']; } } Quote Link to comment Share on other sites More sharing options...
webent Posted June 28, 2008 Author Share Posted June 28, 2008 My time ran out for me to edit my last post, but I had a very small syntaxical error... On the first line of the first query, the table should be "$local_database.featured_products" and the "WHERE" clause removed... here is the corrected query in total... $result = mysql_query("SELECT SKU FROM $local_database.featured_products", $b_link); while ($row = mysql_fetch_assoc($result)) { $SKU = $row['SKU']; $sub_result = mysql_query("SELECT PRODUCT_IMAGE, MSRP, PRODUCT_NAME FROM domain_supplier.$single_product_line ORDER BY RAND() WHERE SKU = '$row[sKU]'", $a_link); while ($sub_row = mysql_fetch_assoc($sub_result)) { $PRODUCT_IMAGE = $sub_row['PRODUCT_IMAGE']; $MSRP = $sub_row['MSRP']; $PRODUCT_NAME = $sub_row['PRODUCT_NAME']; } } Quote Link to comment Share on other sites More sharing options...
fenway Posted July 1, 2008 Share Posted July 1, 2008 Unfortunately, it's not possible to use dynamic table names. Quote Link to comment Share on other sites More sharing options...
webent Posted July 1, 2008 Author Share Posted July 1, 2008 I use it as is, and it works fine, just thought that a Join would be better... If you wouldn't mind too awful much then, could you please tell them to fix it so that we can use dynamic table names in Joins... Quote Link to comment Share on other sites More sharing options...
fenway Posted July 2, 2008 Share Posted July 2, 2008 If you wouldn't mind too awful much then, could you please tell them to fix it so that we can use dynamic table names in Joins... It's virtually impossible to implement this feature -- it would make calculating the join plan practically impossible. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.