Subject | Re: Small Update SQL trick (problem) |
---|---|
Author | Adam |
Post date | 2005-12-27T23:14:01Z |
--- In firebird-support@yahoogroups.com, "majstoru" <majstoru@y...> wrote:
UPDATE Article a
SET a.Price = (SELECT d.Price FROM Document d WHERE d.Article =
a.Article.id);
Otherwise no.
Obviously, Document.Article must be unique or you will need to use
some other operator (like sum, min, first 1, etc) to ensure you only
get a singular value.
Adam
>Only if your suggested query works
> Hi Adam,
>
> I'll try simplier.
>
> > > Here is sample data:
> > > Article
> > > id name price
> > > 1 name1 10.00
> > > 2 name2 20.00
> > > 3 name3 30.00
> > >
> > > Document
> > > article qty newprice
> > > 1 10 15.00
> > > 2 10 25.00
> > > 3 10 35.00
> > >
>
> SQL that I need must upade price from table document UPDATE Article
> SET Article.Price = (SELECT Price FROM Document WHERE Document.Article
> = Article.id);
>
> My SQL shoul be work like this:
> for i := 1 to Document.recordcount
> begin
> UPDATE Article SET Article.Price = (SELECT Price FROM Document WHERE
> Document.Article = Article.id);
> end
>
> Is this posible in one SQL statment.
>
> P.S. My english is vey bad, but I'm trying to represent my problem
> with Delphi code below!
>
> Thanks again
>
UPDATE Article a
SET a.Price = (SELECT d.Price FROM Document d WHERE d.Article =
a.Article.id);
Otherwise no.
Obviously, Document.Article must be unique or you will need to use
some other operator (like sum, min, first 1, etc) to ensure you only
get a singular value.
Adam