Search code examples
mysqlsqlsql-serversqlanywhere

Update a column based on two matching values of a column in two tables


I have two questions which if someone can help me it would be great and would be a great learning for me.

  1. I have two tables and my requirement is to update a column A of Table 1 value only for those rows for which the column B has values same as column B of Table2.

    I am looking for an optimized query for this in SQL.

    UPDATE DBA.COM, DBA.MEN
    SET DBA.COM.ND_MAN=''
    WHERE DBA.MEN
    

    After this, I couldn't select column names in where condition.

  2. The problem I am finding in Column B of both the tables is, it is unique identified (GUID) from the UI. So, when I copy the cell value from "SQL Anywhere" Interactive SQL Editor, it displays the column value copied as follows:

    0x99e2f2a23f9946acb0ceb374a627b142
    

    and not as 99e2f2a23f9946acb0ceb374a627b142.

    However, both the table's column value when I copy, it is starting with 0x. So will it not pose any problem I guess?

Or how to rectify it in above query which you will create for question 1?


Solution

  • You need to join and update something as

    update table1 t1
    join table2 t2 on t1.B = t2.B
    set t1.A = 'some value'