I have a table TICKET and SEGMENTS, in the table TICKET there is a column dop_zbor_naprav where I add a number. In the SEGMENTS table there is a column BASICFARE where to have the desired data (GC10) to update the column dop_zbor_naprav in the table TICKET. I want if in the SEGMENTS table in the BASICFARE column there was a given "GC10" updated the TICKET table in the dop_zbor_naprav column with the number I needed. Guys help with the request very much I ask.

Like this request, I know that this request does not work!

update TICKET set dop_zbor_naprav='300' where = (select from SEGMENTS where BASICFARE like '%GC10%') 
  • where = ( ...) and what exactly is equal from the first table to the value that the subquery returns? to the left of the equal sign, there must be something to stand ... And select from SEGMENTS cannot be, between the words select and from it must be indicated what exactly you want to get from the table. - Mike
  • And the text of the question is nothing at all clear. Perhaps because you are confusing the concepts row and column. One could understand what a dop_zbor_naprav column is, but there can be no rows with any name in the database - Mike
  • I want if in the SEGMENTS table in the BASICFARE column there was a value = GC10 then update the TICKET table in the dop_zbor_naprav column - delphi
  • one
    both tables have identical columns with the value TICKET-BSONUM in SEGMENTS-BSONUM - delphi
  • one
    Although if your task in Russian sounds like " set the column dop_zbor_naprav = 300 in the TICKET table for those records for which the SEGMENTS table has records with the same BSONUM and BASICFARE containing GC10 ", then update TICKET set dop_zbor_naprav='300' where BSONUM IN (select BSONUM from SEGMENTS where BASICFARE like '%GC10%') . The main thing is to first formulate the task correctly ... - Mike

2 answers 2

 update t set dop_zbor_naprav='300' FROM TICKET t JOIN SEGMENTS s ON t.BSONUM = s.BSONUM where s.BASICFARE like '%GC10%' 

    option from Mike also works, thanks to all for the answers.

     UPDATE TICKET SET dop_zbor_naprav='300' WHERE BSONUM IN (SELECT BSONUM FROM SEGMENTS WHERE BASICFARE LIKE'%GC10%')