Update SQL statement only if two values match in another table

user3498953

I have been searching for this scenario that has come across my desk, I have been searching reference sites but haven't had luck creating the correct SQL statement to complete this task.

Here is the PSEUDO code for the scenario.

UPDATE TABLE1
SET TABLE1.ID = TABLE1.From_ID,
    TABLE1.VALUE = 'ALL'
WHERE TABLE1.From_ID = TABLE2.ID
  AND TABLE2.NAME = 'TEST'

Basically I need to update two columns in TABLE1 only if the id from TABLE1 matches the ID's in the TABLE2 and the description column in TABLE2 equals to a string value the caveat is that TABL1 columns can't be change only if there is a correlation between the ID's from TABLE1 and TABLE2 and in TABLE2 that ID correlates to description column for a specific string value. Below is table structure and end result I'm trying to get too.

TABLE1:

FIELD_ID    CONDITIONAL_VALUE   FROM_FIELDID
--------------------------------------------   
   1        TEST                   3
   7        TEST                   4
   5        ANY                    7

TABLE2:

FIELD_ID   Description
----------------------------------------------
   3       BLUE
   4       BLUE
   7       RED
dpw

In Transact-SQL (SQL Server's dialect of SQL), you need a FROM clause in your SQL if you specify more than the table you're trying to update.

update TABLE1.ID set TABLE1.ID = TABLE1.From_ID , TABLE1.VALUE = 'ALL' from TABLE1, TABLE2 where TABLE1.From_ID = TABLE2.ID AND TABLE2.NAME = ''TEST

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL update statement match only the first row

From Dev

SQL statement to combine both fields in one table that match the id element in another table

From Dev

Update sql table daily with values from another table

From Dev

Update one table based on values in another table using case statement (MYSQL)

From Dev

UPDATE table with two different values

From Dev

How to write sql statement to newly added column with another table values?

From Dev

Update two columns values in a table based on another column value in different table

From Dev

How to get an Update Statement to change the values depending on entries from another Table

From Dev

SQL - Update table values from values in another table

From Dev

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

From Dev

sql update table - statement not working

From Dev

SQL AVG statement another table

From Dev

Matching two values in a table to another value in a table sql

From Dev

SQL: Lookup values in another table and update them

From Dev

Need an update statement that multiplies two column values from diffrent table in mysql

From Dev

UPDATE one SQL table based on equality of two columns with two columns from another table

From Dev

Return best values of two SQL tables along with the values from table 1 that has no match in table2

From Dev

SQL update statement for two tables

From Dev

MySQL update table only with the highest values of another table

From Dev

update value from a table if from other two table values match

From Dev

Update statement with select to another table

From Dev

Using a Case statement to update another table

From Dev

SQL update values in one table to match values of another table in Oracle SQL Developer

From Dev

update values in a string to another table

From Dev

Matching two values in a table to another value in a table sql

From Dev

SQL Comparing Two Columns in same table and update in another table

From Dev

SQL update statement based unique value in another table

From Dev

MS Access: Update the values in a table to match the ID fields of another table

From Dev

Update table with values of another table

Related Related

  1. 1

    MySQL update statement match only the first row

  2. 2

    SQL statement to combine both fields in one table that match the id element in another table

  3. 3

    Update sql table daily with values from another table

  4. 4

    Update one table based on values in another table using case statement (MYSQL)

  5. 5

    UPDATE table with two different values

  6. 6

    How to write sql statement to newly added column with another table values?

  7. 7

    Update two columns values in a table based on another column value in different table

  8. 8

    How to get an Update Statement to change the values depending on entries from another Table

  9. 9

    SQL - Update table values from values in another table

  10. 10

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

  11. 11

    sql update table - statement not working

  12. 12

    SQL AVG statement another table

  13. 13

    Matching two values in a table to another value in a table sql

  14. 14

    SQL: Lookup values in another table and update them

  15. 15

    Need an update statement that multiplies two column values from diffrent table in mysql

  16. 16

    UPDATE one SQL table based on equality of two columns with two columns from another table

  17. 17

    Return best values of two SQL tables along with the values from table 1 that has no match in table2

  18. 18

    SQL update statement for two tables

  19. 19

    MySQL update table only with the highest values of another table

  20. 20

    update value from a table if from other two table values match

  21. 21

    Update statement with select to another table

  22. 22

    Using a Case statement to update another table

  23. 23

    SQL update values in one table to match values of another table in Oracle SQL Developer

  24. 24

    update values in a string to another table

  25. 25

    Matching two values in a table to another value in a table sql

  26. 26

    SQL Comparing Two Columns in same table and update in another table

  27. 27

    SQL update statement based unique value in another table

  28. 28

    MS Access: Update the values in a table to match the ID fields of another table

  29. 29

    Update table with values of another table

HotTag

Archive