Reputation: 15
Can someone please tell me how can I merge these two queries into one Query?
I have already tried this code but the problem here that it does not update the Adserver table.
with first as (
select *, c_date = Current_date() from FRIDAY.Adserver where C_date IS NULL
),
second as (
select * from FRIDAY.Adserver JOIN FRIDAY.Matching_Table
ON Adserver.Placement_ExtID = Matching_Table.string_field_0
),
Tird As(
Select *, CONCAT(Cast(Date as String),"-",Second.string_field_0) AS New_IDS from Second
) Select * from Tird
First I need to update the Adserver Table with the current Date:
QUERY 1: UPDATE FRIDAY.Adserver SET C_date() = CURRENT_Date() Where C_date IS NULL ;
And then I would only pick the data with the current date:
QUERY 2:
With First As( select * from FRIDAY.Adserver where C_date = Current_date() ), Second As( select * from First JOIN FRIDAY.Matching_Table1 ON First.Placement_ExtID = Matching_Table1.string_field_1 OR First.Placement_ExtID = Matching_Table1.string_field_0 ), Tird As( Select *, CONCAT(Cast(Date as String),"-",Second.string_field_0) AS New_IDS from Second ) Select * from Tird
Is there anyway to combine the above Query 1 and Query 2?
Upvotes: 0
Views: 84
Reputation: 2798
That's not possible.
A query can either change data (INSERT, UPDATE, DELETE) or return data (SELECT). To do both "at the same time" code is necessary. But this depends on the used DB server.
For example, you could create a function that first executes the UPDATE statement and then returns the data from the SELECT statement. But as I said, if and how this is possible depends on the DB system.
Upvotes: 1