Here's the scenario, table 1 is one-to-many to table 2, and table 2 is one-to-many with table3. Table 3's records are assigned to table 1 at creation, and assigned to table 2 on an action in a later process (this process). At the time of the queries both table 1 and table 2's primary keys are known. If I run an UPDATE
followed by a SELECT
in the same transaction will the SELECT
reflect the UPDATE
? And when I fetch results is the UPDATE
going to mess with that?
SQL:
UPDATE table3
SET fk_table2 = ?
WHERE fk_table1 = ? AND fk_table2 IS NULL;
SELECT field1, field2, field3, field4,
COALESCE(field5, (SELECT default_table3_field5 FROM table1 WHERE table1.pk = table3.fk_table_1)) AS field5
FROM table3
WHERE fk_table1 = ? AND fk_table2 = ?;
PHP:
$prep = $pdo->prepare($sql);
$prep->execute([
$table2_pk,
$table1_pk,
$table1_pk,
$table2_pk
]);
$detail = $prep->fetchAll(PDO::FETCH_ASSOC);