Hi, everyone,
I am trying to merge two tables together, and only want to keep records that don't exist in both tables.
This is my currenct approach (which is obviously PAINFULLY slow and inefficient):
//Select all of the "permanent" order data.
$q = 'SELECT order_id FROM orders';
$r = mysql_query($q) or die(mysql_error());
//From the results, form a query to select only new records from the "temporary" order data.
$q1 = 'SELECT * FROM orders_temp WHERE order_id != 0';
while ($row = mysql_fetch_assoc($r)) {
$q1 .= ' AND order_id != ' . $row['order_id'];
}
$r1 = mysql_query($q1) or die(mysql_error());
//
while ($row1 = mysql_fetch_assoc($r1)) {
$q3 = 'INSERT INTO orders (
order_id,
invoice_num,
subtotal,
email
) VALUES (
' . $row1['order_id'] . ',
"' . $row1['invoice_num'] . '",
' . $row1['subtotal'] . ',
"' . $row1['email'] . '"
)';
$r3 = mysql_query($q3) or die(mysql_error());
}
Thanks for any help!