I have two update query , both are using same condition to get data. Once one query run the condition won't bale to return any record. The first query
UPDATE catentdesc
SET PUBLISHED = 0
WHERE CATENTRY_ID IN (
SELECT CATENTRY.CATENTRY_ID
FROM CATENTDESC,
CATENTRY
WHERE CATENTRY.catenttype_id = 'ProductBean'
AND CATENTDESC.CATENTRY_ID = CATENTRY.CATENTRY_ID
AND catentry.buyable = 1
AND catentdesc.published = 1
AND CATENTRY.CATENTRY_ID IN (
SELECT CATENTRY_ID
FROM CATGPENREL
WHERE CATALOG_ID = 10001
)
AND catentry.markfordelete = 0 minus
SELECT CATENTRY.CATENTRY_ID
FROM CATENTDESC,
CATENTRY
WHERE CATENTRY.catenttype_id = 'ProductBean'
AND CATENTDESC.CATENTRY_ID = CATENTRY.CATENTRY_ID
AND catentry.buyable = 1
AND catentdesc.published = 1
AND CATENTRY.CATENTRY_ID IN (
SELECT CATENTRY_ID
FROM CATGPENREL
WHERE CATALOG_ID = 10051
)
AND catentry.markfordelete = 0
)
The second query
UPDATE catentry
SET CATENTRY.BUYABLE = 0
WHERE CATENTRY_ID IN (
SELECT CATENTRY.CATENTRY_ID
FROM CATENTDESC,
CATENTRY
WHERE CATENTRY.catenttype_id = 'ProductBean'
AND CATENTDESC.CATENTRY_ID = CATENTRY.CATENTRY_ID
AND catentry.buyable = 1
AND catentdesc.published = 1
AND CATENTRY.CATENTRY_ID IN (
SELECT CATENTRY_ID
FROM CATGPENREL
WHERE CATALOG_ID = 10001
)
AND catentry.markfordelete = 0 minus
SELECT CATENTRY.CATENTRY_ID
FROM CATENTDESC,
CATENTRY
WHERE CATENTRY.catenttype_id = 'ProductBean'
AND CATENTDESC.CATENTRY_ID = CATENTRY.CATENTRY_ID
AND catentry.buyable = 1
AND catentdesc.published = 1
AND CATENTRY.CATENTRY_ID IN (
SELECT CATENTRY_ID
FROM CATGPENREL
WHERE CATALOG_ID = 10051
)
AND catentry.markfordelete = 0
)
The problem is I need to update catentry and catentdesc , but if one update another one I am not able update because the condition query won't return any result.
It is possible with a procedure , by storing the result and update the table. But I am looking for a simpler way, can any one please help me.
Is there any way update both table at a time in DB2 ?
Since you don't specify a platform, I'm going to assume DB2 for Linux/Unix/Windows. If this isn't correct, it may still work on other Platforms, but I'm not sure.
You could declare a temporary table, and store off the results to use in your updates later.
Additionally, I think I was able to simplify your criteria query some by using a
LEFT JOIN
. It looks like you are taking all theCATENTRIES
that are from catalog10001
, and then removing the entries (with the same criteria) that also exist in10051
. If that is the case, then theLEFT JOIN
below should do the same thing. I can't really test it (without sample data), so you might want to test it yourself and ensure the results. :)