Update SQLite table based on data in another table

Khurram Majeed

I have two tables in SQLite which look like this

TABLE_X    
____________________
| id | C1 | C2 | C3 | C4 |
| 10 | 99 | 03 | 04 | 00 |
| 60 | 88 | 20 | 30 | 40 |


TABLE_Y
___________     
| id | C2 |
| 10 | 11 |
| 60 | 22 |

I am trying to write query to update records on Table X based on records in Table Y The condition for the updateis something like the following

update table_x
   set table_x.c1 = 100,
       table_x.c2 = table_y.c2
 where table_x.id = table_y.id

But when I try to do this I get an error message saying

NO such column: table_y.c2

user2864740

The deleted answer was correct about the cause of the error: a relation identifier must be introduced (e.g. with FROM/JOIN) in a query before it can be used.

While SQLite does not support UPDATE..JOIN (so there is no way to introduce the lookup relation directly), a dependent sub-query can be used to simulate the effect:

update table_x
   set c1 = 100,
       c2 = (select y.c2 from table_y as y
             where y.id = table_x.id)

Note that unlike a proper UPDATE..JOIN, if the sub-select fails to find a match then NULL will be assigned.

YMMV.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sqlite - Update table rows based on another data in the row

From Dev

update table based on another tables value in sqLite

From Dev

update data.table based on values in another data.table

From Dev

Update a data.table based on another data table

From Dev

Fast update or create a table based on data from another table

From Dev

SQLite - Update a column based on values from another table's columns

From Java

How to update another table based on foreign table

From Dev

Update table with another table based on cell value

From Dev

How to update table based on another table column?

From Dev

Update a column in a table based on column in another table

From Dev

Update table based on conditions from another table

From Dev

Update table based on another table with conditions

From Dev

Update one table by aggregating data of another table

From Dev

Select data based on another table

From Dev

Trigger to update table based on another table update in mysql

From Dev

mysql update and insert statements based on another table

From Dev

informix update based on values in another table

From Dev

Update another table based on latest record

From Dev

Trigger to update a count based on another table

From Dev

How to update one table based on aggregate query form another table

From Dev

SQL set operation to update table based on values on another table

From Dev

R update table column based on search string from another table

From Dev

Update column in one table based on value in another table in mysql

From Dev

Update mysql one table from another table based on dates

From Dev

Update mysql table based on another table and file input

From Dev

Update multiple columns in one table based on values in another table in mysql

From Dev

R update table column based on search string from another table

From Dev

MS SQL Server, Create and update a table based on another table

From Dev

Update, Insert and Delete rows in a table based on changes in another table

Related Related

  1. 1

    Sqlite - Update table rows based on another data in the row

  2. 2

    update table based on another tables value in sqLite

  3. 3

    update data.table based on values in another data.table

  4. 4

    Update a data.table based on another data table

  5. 5

    Fast update or create a table based on data from another table

  6. 6

    SQLite - Update a column based on values from another table's columns

  7. 7

    How to update another table based on foreign table

  8. 8

    Update table with another table based on cell value

  9. 9

    How to update table based on another table column?

  10. 10

    Update a column in a table based on column in another table

  11. 11

    Update table based on conditions from another table

  12. 12

    Update table based on another table with conditions

  13. 13

    Update one table by aggregating data of another table

  14. 14

    Select data based on another table

  15. 15

    Trigger to update table based on another table update in mysql

  16. 16

    mysql update and insert statements based on another table

  17. 17

    informix update based on values in another table

  18. 18

    Update another table based on latest record

  19. 19

    Trigger to update a count based on another table

  20. 20

    How to update one table based on aggregate query form another table

  21. 21

    SQL set operation to update table based on values on another table

  22. 22

    R update table column based on search string from another table

  23. 23

    Update column in one table based on value in another table in mysql

  24. 24

    Update mysql one table from another table based on dates

  25. 25

    Update mysql table based on another table and file input

  26. 26

    Update multiple columns in one table based on values in another table in mysql

  27. 27

    R update table column based on search string from another table

  28. 28

    MS SQL Server, Create and update a table based on another table

  29. 29

    Update, Insert and Delete rows in a table based on changes in another table

HotTag

Archive