Eugeny89
Eugeny89

Reputation: 3731

php+mysql: copying a row from one table to another

I'm having two tables table(fieldA, fieldB, fieldC) and log_table(id, fieldA, fieldB, fieldC). Is it possible to copy a row from table to log_table with one (not two: select and insert) query?

Thank you in advance!

Upvotes: 0

Views: 214

Answers (2)

Andrius Naruševičius
Andrius Naruševičius

Reputation: 8578

You can use a single INSERT statement passing a SELECT query instead of a list of constant values:

INSERT INTO log_table (SELECT fieldA, fieldB, fieldC FROM table)

Upvotes: 3

Arion
Arion

Reputation: 31249

I am not sure what you want. But maybe something like this:

INSERT INTO log_table( fieldA, fieldB, fieldC)
SELECT fieldA, fieldB, fieldC FROM table

Upvotes: 1

Related Questions