Board index » delphi » Updating a field from one table from another table

Updating a field from one table from another table

All of the update examples that I can find show the trivial example "update
table1 set f2 = 'some string' where ...  "

I want to do this, which seems to work in many variants of SQL, but not in
Local SQL:

update table1
 set f2 = table2.f2 from  table2
 where table1.f1 = table2.f1

Surely there's a way to do this

--
Michael D. Spence
Mockingbird Data Systems, Inc.

 

Re:Updating a field from one table from another table


All of the update examples that I can find show the trivial example "update
table1 set f2 = 'some string' where ...  "

I want to do this, which seems to work in many variants of SQL, but not in
Local SQL:

update table1
 set f2 = table2.f2 from  table2
 where table1.f1 = table2.f1

Surely there's a way to do this

--
Michael D. Spence
Mockingbird Data Systems, Inc.

Re:Updating a field from one table from another table


On Fri, 17 Mar 2000 08:48:49 -0500, "Michael D. Spence"

Quote
<spence&nosp...@panix.com> wrote:
>All of the update examples that I can find show the trivial example "update
>table1 set f2 = 'some string' where ...  "

>I want to do this, which seems to work in many variants of SQL, but not in
>Local SQL:

>update table1
> set f2 = table2.f2 from  table2
> where table1.f1 = table2.f1

You need to use an embedded SELECT statement (a subquery) to reprent
the source table.

  UPDATE Table1
  SET F2 =
    (SELECT DISTINCT Table2.f2
    from Table2
    WHERE (Table2.F1 = Table1.F1))

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\
Steve Koterski                    "If you aren't fired with
Technical Publications            enthusiasm, you will be
Borland                           fired with enthusiasm."
                              -- Vince Lombardi (1913-1970)

Other Threads