Re: [SQL] Simple SQL-syntax

2001-08-20 Thread Josh Berkus
Folks, Ooops! Let me correct that example: UPDATE invoice SET invoice_total = total_of_items FROM (SELECT invoice_id, sum(item_amount) AS total_of_items FROM invoice_items) iit WHERE iit.invoice_id = invoices.id; Sorry to lead people astray. -Josh __AGLIO DATABASE SOLUTIONS___

Re: [SQL] Simple SQL-syntax

2001-08-20 Thread Josh Berkus
Robby, > Do you know if, internally there's any difference between > > UPDATE A,B SET a.f1 = b.f1 WHERE a.i = b.i; > > -and- > > UPDATE A SET a.f1 = b.f2 FROM B WHERE a.i = b.i; > > Just wondering why the SQL standard would be broken in this > case---and if there's any reason to learn this

Re: [SQL] Simple SQL-syntax

2001-08-20 Thread Josh Berkus
Robby, > 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: Actually, Postgres *does* support UPDATE ... FROM. I use it quite a bit. The syntax can b

RE: [SQL] Simple SQL-syntax

2001-08-20 Thread Robby Slaughter
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: >IndexText

Re: [SQL] Simple SQL-syntax

2001-08-20 Thread Josh Berkus
Fredrik, > I have a very simple sql-question from an sql-beginner: Sure. Keep in mind that there is a pgsql-newbie list. Also quite a few good books on the topic, including: Database Design for Mere Mortals and SQL for Smarties. > Then I want to change all occurences of NrA in Table A to NrB.

RE: [SQL] Simple SQL-syntax

2001-08-20 Thread Michael Ansley (UK)
Title: RE: [SQL] Simple SQL-syntax -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Probably something like:   UPDATE tableA SET tableA.nrA = (SELECT B.nrB FROM tableB B WHERE tableA.nrA = B.nrA);   Let me know...     MikeA     - -Original Message- From: Fredrik Thunberg [mailto

[SQL] Simple SQL-syntax

2001-08-20 Thread Fredrik Thunberg
Hello.   I have a very simple sql-question from an sql-beginner:   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...   I've tried:   UPDATE tableA Set tableA.nrA