dbTalk Databases Forums  

sql update max smartries

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss sql update max smartries in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Vic Cekvenich
 
Posts: n/a

Default sql update max smartries - 10-21-2004 , 06:14 PM






I am trying to write a sigle command to update the max number from detail.

Something like:
update group set max_msgid=max(c.msgid)
from group g, content c
where g.id=c.g_id

So group is master, content is detail. I want group to stroe max(msgid)
from content.

Syntax help plz?
..V


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #2  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: sql update max smartries - 10-23-2004 , 06:16 PM






On Thu, Oct 21, 2004 at 18:14:15 -0500,
Vic Cekvenich <cekvenich.vic (AT) portalvu (DOT) com> wrote:
Quote:
I am trying to write a sigle command to update the max number from detail.

Something like:
update group set max_msgid=max(c.msgid)
from group g, content c
where g.id=c.g_id

So group is master, content is detail. I want group to stroe max(msgid)
from content.
You don't want to put 'group' in the from clause, you will then be joining
'group' with itself (in addition to content).
Also you really don't want to join 'group' and 'content', but rather
'group' and (select c.g_id, max(c.msgid) from content group by g_id).
So the query should look something like (I didn't test this):
UPDATE "group" SET max_msgid=g.msgid
FROM (SELECT c.g_id, max(c.msgid) AS msgid FROM "content" c GROUP BY g_id) AS g
WHERE "group".id = g.g_id;

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.