473,402 Members | 2,055 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,402 software developers and data experts.

Correlated Update

1
Hi all.

Can anybody suggest an Oracle equivalent to the following sql query :



UPDATE Profile
SET LastSavedSearch =
(
SELECT TOP 1 ss.SavedSearch--, MAX(DATEADD(s, ssb.StartTime, ssb.StartDate))
FROM Profile p
INNER JOIN ProfileFile pf ON pf.ProfileFile = p.ProfileFile
INNER JOIN SavedSearchLoadScheduleItem lsi ON lsi.DmsId = pf.DmsId
INNER JOIN SavedSearchLoadSchedule ls ON ls.SavedSearchLoadScheduleItem = lsi.SavedSearchLoadScheduleItem
INNER JOIN SavedSearchBulk ssb ON ssb.SavedSearchBulk = ls.SavedSearchBulk
INNER JOIN SavedSearch ss ON ss.SavedSearch = ssb.SavedSearch
WHERE (p.LastSavedSearch IS NULL) AND (ss.ProfileDms = p.ProfileDms)
AND (p.Profile = p1.Profile)
GROUP BY ss.SavedSearch
ORDER BY MAX(cast((ssb.StartDate + ssb.StartTime/86400) as timestamp)) DESC
)
FROM Profile p1
WHERE p1.LastSavedSearch IS NULL;



Thanks and regards,
Naveen
Mar 21 '07 #1
1 3603
Dave44
153 100+
Hi all.

Can anybody suggest an Oracle equivalent to the following sql query :



UPDATE Profile
SET LastSavedSearch =
(
SELECT TOP 1 ss.SavedSearch--, MAX(DATEADD(s, ssb.StartTime, ssb.StartDate))
FROM Profile p
INNER JOIN ProfileFile pf ON pf.ProfileFile = p.ProfileFile
INNER JOIN SavedSearchLoadScheduleItem lsi ON lsi.DmsId = pf.DmsId
INNER JOIN SavedSearchLoadSchedule ls ON ls.SavedSearchLoadScheduleItem = lsi.SavedSearchLoadScheduleItem
INNER JOIN SavedSearchBulk ssb ON ssb.SavedSearchBulk = ls.SavedSearchBulk
INNER JOIN SavedSearch ss ON ss.SavedSearch = ssb.SavedSearch
WHERE (p.LastSavedSearch IS NULL) AND (ss.ProfileDms = p.ProfileDms)
AND (p.Profile = p1.Profile)
GROUP BY ss.SavedSearch
ORDER BY MAX(cast((ssb.StartDate + ssb.StartTime/86400) as timestamp)) DESC
)
FROM Profile p1
WHERE p1.LastSavedSearch IS NULL;



Thanks and regards,
Naveen

Ok first since there are no table scripts here i have little knowledge of your tables and since there is no requirement given i can only assume that your query worked in some other environment.

Given the above caveat, I think this is in line with what you were doing:
Expand|Select|Wrap|Line Numbers
  1. Update profile p
  2. set  lastsavedsearch = (select max(ss.savedsearch)
  3.                         from   profilefile pf,
  4.                                INNER JOIN SavedSearchLoadScheduleItem lsi ON lsi.DmsId = pf.DmsId
  5.                                INNER JOIN SavedSearchLoadSchedule ls ON ls.SavedSearchLoadScheduleItem = lsi.SavedSearchLoadScheduleItem
  6.                                INNER JOIN SavedSearchBulk ssb ON ssb.SavedSearchBulk = ls.SavedSearchBulk
  7.                                INNER JOIN SavedSearch ss ON ss.SavedSearch = ssb.SavedSearch
  8.                         where  p.profiledms = ss.profiledms
  9.                         and    pf.ProfileFile = p.ProfileFile )
  10. where p.lastsavedsearch is null
  11.  
Also just to note. I havent seen an instance yet where you need to sort a sub query in an update.

let me know how this works
Mar 22 '07 #2

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

Similar topics

0
by: Murali | last post by:
Hi All I was reading thro the posting(s) of Thomas Kyte and his nifty approach to doing updates without the need for unnecessary correlated subqueries. An alternative to correlated subquery...
1
by: Jason | last post by:
Hello All, I have a SQL Query with multiple correlated Subqueries in it. When it gets executed it runs rather slow due to the size of the QT table. Does anybody have any suggestions how to alter...
1
by: Mike L. Bell | last post by:
Query: update table1 t1 set end_time = ( select end_time from table2 t2 where t2.key1 = t1.key1 and t2.key2 = t1.key2 ) where exists
8
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A...
1
by: Mike MacSween | last post by:
tblProductions one to many to tblEvents tblEvents contains StartDate I want a report where the data are grouped by tblProductions.ProdID, and sorted by the earliest date in each Production. ...
4
by: sql_server_user | last post by:
Hi, I have a history table with about 400 million rows, with a unique composite nonclustered index on two columns (object id and time period) which is used for most of the queries into the...
5
by: steven.fafel | last post by:
I am running 2 versions of a correlated subquery. The two version differ slightly in design but differ tremendously in performance....if anyone can answer this, you would be awesome. The "bad"...
1
by: jgreve | last post by:
(aix 5.1, db2 8.1.6) Consider this toy example: -------------------- create table foo ( alpha int, beta int ); insert into foo ( 100, -1 ); insert into foo ( 200, -1 ); insert into foo (...
4
by: muzu1232004 | last post by:
Can anyone explain me when we use correlated subqueries rather than nested subqueries. Do all the correlated subqueries can be written in nested subqueries form as well ? What are the major...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.