?
Solved

UPDATE SELECT WITH GROUP BY

Posted on 2004-09-29
3
Medium Priority
?
4,406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
granbajo earned 1000 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

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

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

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
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 video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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