Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UPDATE SELECT WITH GROUP BY

Posted on 2004-09-29
3
Medium Priority
?
4,424 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 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