Solved

UPDATE SELECT WITH GROUP BY

Posted on 2004-09-29
3
4,353 Views
Last Modified: 2012-08-13
I have this sql statement which is not working, can u please explain why?
update table a set col1_timestamp=
(select max(b.col_timestamp) from  a,b
where a.col1=b.col2
and
a.col1='A'
and b.col2='C'
group by a.col3)
where exists
(select * from  a,b
where a.col1=b.col2
and
a.col1='A'
and b.col2='C'
group by a.col3)
I am getting sql0811, more than 1 value
0
Comment
Question by:ghp7000
3 Comments
 
LVL 3

Accepted Solution

by:
granbajo earned 250 total points
ID: 12187958

 Mmm...  When you do max and then a group by, you will get 1 value for each result  of the group by clause.  In this case the max a.col1 for each different value of a.col3.  Having said that, you are asking for a.col1 and b.col2 to be of the same value, and the you ask for each one of them to have a different value, so I would expect that your query would not return anything.   Maybe there is something I am missing.

  What do you get as a result when you run the SELECT on its own?
0
 
LVL 13

Author Comment

by:ghp7000
ID: 12193079
thanks for responding to my post which is a completely stupid one as I only have about 10 thousand templates to work with that do what I want, my post just reflects my age, old and outdated (:
0
 
LVL 5

Expert Comment

by:danirk2
ID: 23002570
Something similar to the following?

UPDATE t2
      set t2.price =
            (
                  SELECT SUM(cost) FROM t1      
                  WHERE t2.part = t1.part
                  GROUP BY part
            )
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DB2 iSeries Combine Results of 2 Selects (nested Join?) ? 2 76
DB2 V9.7 restore 5 42
DB2 - LOG FILES. 4 51
Shell Script on AIX 7 99
November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question