Q:

Problems with mysql query syntax? Trying to INSERT off of an INNER JOIN

The following code is giving me a vague and unhelpful error:
INSERT INTO database VALUES * FROM dbtemp WHERE dbtemp.number NOT IN (SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price);

I've successfully run other queries on these databases, so I know its just a problem with the syntax of this statement. But for the life of me I can't see what's wrong. Any suggestions/advice would be greatly appreciated.
Thanks!

A:

Should this have been an INSERT INTO SELECT statement?  Your syntax of INSERT INTO database VALUES * is suspect...
INSERT INTO database
  SELECT * FROM dbtemp 
  WHERE dbtemp.number NOT IN (
    SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price
  );

When doing an INSERT SELECT like this, it is advisable to use explicit column names, rather than SELECT *, to be sure they are returned in the correct order:
INSERT INTO database
  SELECT
    col1,
    col2,
    col3
  FROM dbtemp 
  WHERE dbtemp.number NOT IN (
    SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price
  );

