I have two queries.
The first one is..
INSERT INTO balik
( balik_date,
balik_time,
balik_cardID,
balik_status,
balik_type )
select
current_date(),
'00:00:00',
L_CardID,
'BELUM BALIK',
L_Type
FROM
logdetail t1
LEFT JOIN balik t2
ON t1.L_CardID = t2.balik_cardID
WHERE
t1.L_Type = 'IN'
and t1.L_Date = current_date()
AND t2.balik_cardID IS NULL"
and another one is..
UPDATE balik blk
INNER JOIN logdetail ld
ON blk.balik_cardID = ld.L_CardID
and blk.balik_date = current_date()
SET
blk.balik_status = 'SUDAH BALIK',
blk.balik_type = 'OUT',
blk.balik_time = ld.L_Time
WHERE
ld.L_Type = 'OUT'
and ld.L_Date = current_date()
My problem is that when I execute the first and second query nothing happens unless I delete all records in my table beforehand. In that case both queries are executed and work like a charm.
Why is this happening?
From what I remember, you can’t do an insert into a table that is a result of a query that may be an impact of what you are inserting… So, it MIGHT help if the select was “wrapped” inside another layer so the inner query is completely processed FIRST and thus not impacted by the inserts.
I would alter the syntax on the update to more closely match that of the SQL Syntax per documentation… list the tables comma separated, then apply join conditions in the WHERE clause
Yeah, essentially the same thing, but might be interpretation issues.