0

If I have this statement,

SELECT table1.*, table2_1.`values` AS val_1 
FROM table1 JOIN table2_1 
ON table1.row_names=table2_1.row_names

I would actually like this the result joined back into table1. Any inclusion of a join statement after SELECT and before FROM gives me an error.

Why can I not save the results to a table, and is it possible to save it back to one of the original tables?

hatmatrix
  • 42,883
  • 45
  • 137
  • 231
  • Ah, apparently SQLite does not support `INTO` statements. But `CREATE TABLE {tablename} AS SELECT {rest}` works. – hatmatrix Dec 07 '11 at 16:49

1 Answers1

1

Because you do it the wrong way. SELECT statement will not modify you data no matter how much you want it. If you want to modify data, you need to use UPDATE statement.

Petr Abdulin
  • 33,883
  • 9
  • 62
  • 96
  • But how can I effectively combine an `UPDATE` with a `JOIN` statement in SQLite? There is an [example using a subquery](http://stackoverflow.com/questions/773441/how-do-i-make-an-update-while-joining-tables-on-sqlite) but the implementation is for a specific and simpler case. – hatmatrix Dec 07 '11 at 16:51
  • As you can see from referenced by you question, SQLite doesn't support `JOIN`s in `UPDATE`. You have to perform each update manually, i.e. iterate thru `table2_1` and for each row, perform `UPDATE` in `table1`. – Petr Abdulin Dec 08 '11 at 03:47