Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question isn't the best, I'll try to help but better questions get better answers.</p> <p>I'll assume you need to keep the tables 3 separate tables (I personally wouldn't, I'd just add a <code>distributor</code> field or similar and put everything in one table).</p> <p>(Judging by your PHP tag, I'll put it in php).<br> I'll provide a rather specific example, but it is important that you understand how it works so you can adapt it.</p> <pre><code>//Dist. A $query = "SELECT * FROM `db`.`table_a` WHERE 1 ORDER BY `sku` DESC"; //Get the list of products $result = mysql_query ($query) or die (mysql_error()); while ( $row = mysql_fetch_assoc($result)) { if ( $row['stock'] != 0 ) { //If we have stock... $query = "SELECT * FROM `final_table` WHERE `sku` LIKE '".$row['sku']."'"; //See if we have the data in the final table $final_result = mysql_query ($query) or die (mysql_error()); if ( mysql_num_rows($final_result) == 0 ) { //Product Not in new table $query = "INSERT INTO `final_table` VALUES ( '".$row['sku']."' [The rest of your values]"; mysql_query ($query) or die (mysql_error()); } if ( mysql_num_rows($final_result) &gt;= 1 ) { //Product In new table $new_row = mysql_fetch_assoc($new_result); //Get the data into an array so we can compare the prices if ( $row['price'] &lt; $final_row['price'] ) { //New price is lower $query = "UPDATE `final_table` SET `dist` = 'A', `price` = '".$row['price']."' [Other Vars that need update] WHERE `sku` LIKE '"$row['sku']"'"; mysql_query ($query) or die (mysql_error()); } } } } </code></pre> <p>Then repeat it for B and C tables, updating the table names and the value that's put in the final db.</p> <p>(I realize I probably violated some conventions in that example, but the concept is there.)</p> <p>This does assume a few things, mainly that <code>sku</code> is some sort of unique index.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload