0

I'm trying to execute the following command through straight sql execution and it runs fine without any errors but it's not actually working.

INSERT INTO log_inventory(CREATED_TIME, PRODUCT_ID, LOG_INV_CHANGE, LOG_INV_ACTION, LOG_INV_NUM_HISTORY, USER_ID)
SELECT now(), p.PRODUCT_ID, p.PRODUCT_INVENTORY, 'Manual Inventory Override', 0, 1
FROM product AS p WHERE p.PRODUCT_INVENTORY != 0;

The select query works because if I run that separately, it returns all the rows I need, but the insert portion doesn't work. Am I missing something?

5
  • What client are you testing this in? The syntax is all correct. Commented Jan 22, 2015 at 21:41
  • InnoDB Mysql, running the sql query inside phpmyadmin and it shows no errors. Commented Jan 22, 2015 at 22:19
  • This is one of those things where you just need to quadruple check that you're working with the right db connection and the table has rows in it. Does the target table already have some rows, or is it empty? Commented Jan 23, 2015 at 0:18
  • Like I said, the select works and returns rows, the target table is empty though. I am definitely working in the right database, especially because I'm in phpmyadmin and it's hard not to be. Commented Jan 23, 2015 at 3:43
  • Wow, idk what I was doing wrong, I think it was just me being tired, it does work. Commented Jan 23, 2015 at 17:11

1 Answer 1

1

Supposing the query has results, try this:

INSERT INTO log_inventory(CREATED_TIME, PRODUCT_ID, LOG_INV_CHANGE, LOG_INV_ACTION, LOG_INV_NUM_HISTORY, USER_ID)
(
    SELECT now(), p.PRODUCT_ID, p.PRODUCT_INVENTORY, 'Manual Inventory Override', 0, 1
    FROM product AS p 
    WHERE p.PRODUCT_INVENTORY != 0
);

Hope that helps

Sign up to request clarification or add additional context in comments.

1 Comment

It was working all along, idk what I was doing wrong. Since your comment made me try again, I'll mark it as answered, sorry!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.