473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Update Query needed to update the existing column

I need to replace one value of a column to another.

Example :

No Update_count Update_time
1 0 2015-02-02 12:23:24
1 0 2015-02-02 12:23:24
1 0 2015-02-02 12:24:25

For a particular No and update count the time should be same , in this case i need to set Max(update_time) as the time for all 3 records , Can someone help please.

Result should be like this :

No Update_count Update_time
1 0 2015-02-02 12:24:25
1 0 2015-02-02 12:24:25
1 0 2015-02-02 12:24:25
Feb 3 '15 #1
11 1395
Rabbit
12,516 Expert Mod 8TB
What problem are you having? Do you not know how to write an update query? Or do you not know how to write a query to retrieve the max value? Or do you not know how to combine the two?
Feb 3 '15 #2
Hi ,

There are lot of numbers in the table , i need to place the max update_time if the update count is same .

For a particular update time and No the update time should be same , if its different then i need to replace it with the Max(update_time) for that update count.

I hope u got my question
Feb 4 '15 #3
Rabbit
12,516 Expert Mod 8TB
I understand the question. I don't understand which part of the question you're having trouble with. Please answer my original questions.
Feb 4 '15 #4
Hi ,

I have retrived the maximum value for each combination of update_count and No.

I don't know how to write an update statement that updates the proper value based on the key combination of Update_count and no.
Feb 4 '15 #5
Rabbit
12,516 Expert Mod 8TB
Ok, so you the problem you are having is that you don't know how to combine the two queries?

Here's an example
Expand|Select|Wrap|Line Numbers
  1. UPDATE t
  2. SET fieldName = x.otherFieldName
  3. FROM
  4.    table1 AS t
  5.  
  6.    INNER JOIN ( ... max query ... ) AS x
  7.    ON t.keyField = x.keyField
Feb 4 '15 #6
Expand|Select|Wrap|Line Numbers
  1. update Xipu.tqx0sn_Change_audit_day as t
  2. set t.Update_time = X.Update_time 
  3. X X X  
  4. select * from (select  Max(A.Update_time) as Update_time , A.Task_number , A.Update  from Xipu.tqx0sn_Change_audit_day A 
  5. join Xipu.tqx0sn_Change_audit_day B 
  6. On A.Task_number = B.Task_number  
  7. And A.Update = B.Update
  8. And A.Update_time <> B.Update_time
  9. group by A.Update , A.Task_number ) X
  10. on t.task_number = X.Task_number
  11. and t.Update = X.Update
This is the query i wrote , how to join both . can u please help.
Feb 5 '15 #7
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

Use my example as a template on how to combine your queries.
Feb 5 '15 #8
I a working in DB2 and i tried ur example and tried and it was not working. can u please edit the query i sent and post it
Feb 5 '15 #9
Rabbit
12,516 Expert Mod 8TB
Please post your attempt at combining the queries.
Feb 5 '15 #10
Expand|Select|Wrap|Line Numbers
  1. update Xipu.tqx0sn_Change_audit_day as t
  2.     set t.Update_time = X.Update_time 
  3.     X X X  
  4.     select * from (select  Max(A.Update_time) as Update_time , A.Task_number , A.Update  from Xipu.tqx0sn_Change_audit_day A 
  5.     join Xipu.tqx0sn_Change_audit_day B 
  6.     On A.Task_number = B.Task_number  
  7.     And A.Update = B.Update
  8.     And A.Update_time <> B.Update_time
  9.     group by A.Update , A.Task_number ) X
  10.     on t.task_number = X.Task_number
  11.     and t.Update = X.Update
  12.  
This is the query i used . in the place of XXX i used 'from' , 'Innerjoin' . none is working
Feb 6 '15 #11
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

Here's what I see wrong in your code:
1) I don't put a table name in the first line. It's only the alias.

2) You didn't subquery your entire query that you use to get the max. In fact, there's no need for you to do an additional select * on your subquery, it is unnecessary.

3) You do an additional join in your subquery that is unnecessary

Try this
Expand|Select|Wrap|Line Numbers
  1. update t
  2. set Update_time = X.Update_time 
  3. from 
  4.     Xipu.tqx0sn_Change_audit_day as t
  5.  
  6.     inner join (
  7.         select Max(A.Update_time) as Update_time, A.Task_number, A.Update 
  8.         from Xipu.tqx0sn_Change_audit_day
  9.         group by A.Update , A.Task_number
  10.     ) X on
  11.         t.task_number = X.Task_number and
  12.         t.Update = X.Update
Feb 6 '15 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ray | last post by:
Hello, This one I think should be easy when you now how but I couldn't get it today. I have to run a kind of double check routine. 1 database, 2 tables. No linking or referential integrity or...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
1
by: Deano | last post by:
Sorry for all the questions lately (I am trying!) :) Here's an interesting one. I need to create 3 records on the many side of a relationship for every record on the parent table. I'm...
5
by: Dave Smithz | last post by:
Hi there, Been working on an evolving DB program for a while now. Suddenly I have come across a situation where I need to update a table based on a group by query. For example, I have a table...
2
by: jrsonner | last post by:
I have multiple entries in one table that I need to update the entries in the current production table with, to revert that data back before a migration so I can migrate that data again. The...
17
luvgis
by: luvgis | last post by:
I'm trying to find a simple way to update a column with sequential numbers without using a recordset. Here is the catch, each agency has a range such as Anaheim - 6,000 range Buena Park - 7,000...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
4
by: nominoo | last post by:
Hi all I've developed a query in access that updates the value of a field, in relation to the value of another field i.e Field one contains a date and the query projects a start date 91 days...
1
by: islandgal | last post by:
-- -- Table structure for table borrower -- DROP TABLE IF EXISTS borrower; CREATE TABLE borrower ( brw_num int(11) NOT NULL default '0', brw_lname varchar(15) default NULL, brw_fname...
7
Brilstern
by: Brilstern | last post by:
I have a database that consist of two primary tables: I have created a button that deletes a patron from the tables INNERJOIN by opening a form requesting the user input the room to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.