Jump to content

Comparing mySQL Tables


rseigel

Recommended Posts

I have two tables that I want to compare.

 

One is a temporary table that includes the product id, quantity, retail price and wholesale price (product feed from my supplier).

 

The other is a permanent table that includes among other things the same product id.

 

I want to see if an id is in the temp table and not the other one (meaning it's a new product).

 

I also want to see if an id is in the permanent table and not in the temp table (meaning it's a discontinued product).

 

I'd like to be able to output these to the web page so that I can address them.

 

I've searched and I'm getting all kinds of different ideas around the web.

 

Can anyone point me in the right direction? Some sample code, a link, a kick in the right direction - any and all answers are much appreciated.

 

Thanks,

 

Ron

Link to comment
Share on other sites

The most straight-forward query would be to use WHERE column NOT IN (sub-query).

 

To find new products - SELECT * FROM temp_table WHERE id NOT IN (SELECT id from permanent_table)

 

To find discontinued products - SELECT * FROM permanent_table WHERE id NOT IN (SELECT id from temp_table)

Link to comment
Share on other sites

Ok, so this is what I'm trying:

 

$result = mysql_query('SELECT * FROM tmp_price_compare WHERE tmp_price_compare.supplier_reference NOT IN (SELECT product_supplier_reference FROM product_supplier)')
or die(mysql_error());
echo "NEW PRODUCTS<br /><br />";
while($row = mysql_fetch_array($result))
 {
 echo "<a href=https://www.mysupplier.com/item/item.lasso?dsc2=" . $row['supplier_reference'] . echo $row['supplier_reference'] . echo"</a><br />";
 }

 

The SELECT itself works perfectly. I'm just having trouble with the output.

 

I'm sure it's something simple. I'm just not seeing the problem.

 

Anyone?

 

Thanks,

 

Ron

Link to comment
Share on other sites

You only need to echo once, since you're concatenating the string. You also need to quote your href attribute, and put text between the opening and closing of the tag. I believe you meant this:

echo "<a href='https://www.mysupplier.com/item/item.lasso?dsc2=" . $row['supplier_reference'] . "'>" . $row['supplier_reference'] ."</a><br />";

 

Or, simply:

echo "<a href='[url="https://www.mysupplier.com/item/item.lasso?dsc2={$row"]https://www.mysuppli...asso?dsc2={$row[/url]['supplier_reference']}'>{$row['supplier_reference']}</a><br />";

Edited by shlumph
Link to comment
Share on other sites

Here's the final result for reference.

 

while($row = mysql_fetch_array($result))
 {
 echo "<a href=https://www.bnfusa.com/item/item.lasso?dsc2=";
 echo $row['supplier_reference'];
 echo ">";
 echo $row['supplier_reference'];
 echo"</a><br />";
 }

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.