Solved

UPDATE SELECT WITH GROUP BY

Posted on 2004-09-29
3
4,330 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now