RE: Simple SQL-syntax - Mailing list pgsql-sql

From Robby Slaughter
Subject RE: Simple SQL-syntax
Date
Msg-id EPEHLKLEHAHLONFOKNHNMEPEDEAA.webmaster@robbyslaughter.com
Whole thread Raw
In response to Simple SQL-syntax  ("Fredrik Thunberg" <fredrik@datessa.se>)
Responses Re: Simple SQL-syntax
List pgsql-sql
Fredrik,

Just for future reference, it's generally a good idea to include a complete
table schema
and some sample data for your tables when asking this kind of question. But
I think I know
what you mean and will try to help you.

>Suppose I have Table A looking something like this:
>Index    Text    NrA

>And Table B like this:
>NrA    NrB

>Then I want to change all occurences of NrA in Table A to NrB...

First of all, your syntax isn't quite right. It's
  UPDATE tablename SET value = value WHERE [conditions];

There's no FROM clause in an update statement. And second, you
need to be careful to make sure all your tokens make sense. You
had an extra "B" in the middle of your statement. Based on this:
 UPDATE tableA,tableB SET tableA.NrA = tableB.NrB WHERE tableA.NrA =
tableB.NrB

should achieve the desired result.

Hope this helps!

-Robby Slaughter



pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Simple SQL-syntax
Next
From: "Grigoriy G. Vovk"
Date:
Subject: Re: Sequential select queries...??