update table with field boolean requirement from another table

Tedy Arian

I have 2 tables

table1

id   kode(boolean)
-----------------
1    false
2    false
3    true

table2

id   num
1    499
2    390
3    500

result : table1

id   kode(boolean)
------------------
1    True
2    True
3    True

I want update table1 kode=true when table2.num < 500

How can this be done for Postgres

Rahul

You can perform a update-join like below. Though not sure if it's SQL Server or Postgres since as commented SQL Server don't have boolean type rather it's bit field.

UPDATE t1
SET t1.kode = true
FROM table1 t1
JOIN table2 t2
    ON t1.id = t2.id
WHERE t2.num < 500;

Here is Postgres syntax:

UPDATE table1 AS t1 
SET kode = true
FROM table2 AS t2
WHERE t1.id = t2.id AND t2.num < 500;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to update a boolean field in Oracle table

From Dev

Add a boolean field if a row exists in another table?

From Dev

Update field taking values sequentially from another table

From Dev

select field from table in another field from another table

From Dev

Update one field in a table in reference to another field on the same table Oracle

From Dev

Update a field in table when I'm updating a field in another table

From Dev

SQLite select average from one table and update average field from another table using trigger

From Dev

Update column type in a table from Boolean to string

From Dev

UPDATE with an avg() from another table?

From Dev

Update id in table from another

From Dev

Update sum from another table

From Dev

MySQL - Update table values from another table

From Dev

Update an oracle table from another table in SAS

From Dev

select from table and update another table SQL

From Dev

SQL : update table from another grouped table

From Dev

POSTGIS - update table from another table

From Dev

Update record in table from another table

From Dev

Update table from another table for certain fields

From Dev

How to update one table from another table?

From Dev

update one table from another selected table

From Dev

SQL : update table from another grouped table

From Dev

Update table based on conditions from another table

From Dev

POSTGIS - update table from another table

From Dev

sql update table from another table snappydata

From Dev

Update field that have duplicates on another table

From Dev

MySQL how to UPDATE a field in one table based on values in another table

From Dev

Update table from another table throught intermediate table Mysql

From Dev

Update Field based on another table's Field values

From Dev

How to update status field from a table

Related Related

  1. 1

    How to update a boolean field in Oracle table

  2. 2

    Add a boolean field if a row exists in another table?

  3. 3

    Update field taking values sequentially from another table

  4. 4

    select field from table in another field from another table

  5. 5

    Update one field in a table in reference to another field on the same table Oracle

  6. 6

    Update a field in table when I'm updating a field in another table

  7. 7

    SQLite select average from one table and update average field from another table using trigger

  8. 8

    Update column type in a table from Boolean to string

  9. 9

    UPDATE with an avg() from another table?

  10. 10

    Update id in table from another

  11. 11

    Update sum from another table

  12. 12

    MySQL - Update table values from another table

  13. 13

    Update an oracle table from another table in SAS

  14. 14

    select from table and update another table SQL

  15. 15

    SQL : update table from another grouped table

  16. 16

    POSTGIS - update table from another table

  17. 17

    Update record in table from another table

  18. 18

    Update table from another table for certain fields

  19. 19

    How to update one table from another table?

  20. 20

    update one table from another selected table

  21. 21

    SQL : update table from another grouped table

  22. 22

    Update table based on conditions from another table

  23. 23

    POSTGIS - update table from another table

  24. 24

    sql update table from another table snappydata

  25. 25

    Update field that have duplicates on another table

  26. 26

    MySQL how to UPDATE a field in one table based on values in another table

  27. 27

    Update table from another table throught intermediate table Mysql

  28. 28

    Update Field based on another table's Field values

  29. 29

    How to update status field from a table

HotTag

Archive