Update the rest of a table from the data contained in a row

1

The following figure explains well what I want to try (and what I tried to do but it did not work):

That is, I need to update some rows of a table with the same data contained in a row (specifically the columns bankId, proj_day and liq_day, in red in the figure above). Note that the id column is equal to the entryID column of the other rows that need to be filled (green in the figure above). The query I mounted did not work, and there are hundreds of data like this that need to be updated that way.

Would anyone give me a light? Thanks!

    
asked by anonymous 16.01.2018 / 01:36

1 answer

0

I found it curious that it did not work, even though I wanted to be declared with two distinct banks, in your question it was not clear if you need to do this by relating two tables to different banks or could be set up with an auto relationship within the same table in just a database. So I took your example and put up a test table as below:

Ileftwiththedefaultvaluenullthefieldsthatshouldbeupdatedthenbuildthequery:

UPDATEfluxASAINNERJOINfluxASBONA.entryId=B.idSETA.proj_day=B.proj_day,A.liq_day=B.liq_day,A.bankId=B.bankIdWHEREA.userid=307ANDA.entryID>0

Icreatedaself-relationshipfollowingyourquery,thedifferenceisthattheabovequeryrelatesittoitself(self-relationship)bytheentryIDfieldand>id.

ThenIranthequerieanditworksperfectasimagebelow:

What I think is wrong is that you are using two distinct databases, possibly you have created a new base so you do not affect the data that is over production and to have a testing environment. As you did not specify the error, in your question, it was difficult to help you more. Utilizing the above self-relationship would work perfect!

    
16.01.2018 / 06:24