Using an Insert-Select Statement
October 31, 2009So, one other thing I want to use this blog for is recording stuff that I forget all the time. I feel like it especially happens with SQL. Why? Not quite sure. I’m a big fan of ActiveRecord, so that gets me away from SQL, so that could be it.
Anyway, I want to record it here because I always forget it: how to INSERT
from one table using a SELECT
from another table.
INSERT INTO sometable (acolumn, anothercolumn)
SELECT someothercolumn, onemorecolumn
FROM adifferenttable
Real simple, but I always end up second-guessing myself (stupidly, I know). Anyway, there it is so I won’t forget it… Hopefully…