I need to make a after insert
trigger that calls a function that takes the last record inserted in a certain table and inserts the ID of that last record into another table according to a select
that returns several ID's. EX:
tb_1
.-------------.
| ID | NOME |
.-------------.
| 1 | A |
| 2 | B |
| 3 | C | <- Último ID inserido
'------'------'
tb_2
.-------------.
| ID | NOME |
|------|------|
| 41 | AAA |
| 42 | BBB |
| 43 | CCC |
| 44 | AAA |
| 45 | AAA |
'------'------'
INSERT INTO tb_3 (tb_1_id,tb_2_id)
VALUES (
(SELECT MAX(ID) FROM tb_1),
(SELECT ID FROM tb_2 WHERE NOME = 'AAA')
)
tb_3
.----------.----------.
| tb_1_id | tb_2_id |
|----------|----------|
| 3 | 41 |
| 3 | 44 |
| 3 | 45 |
'----------'----------'
How to make a insert
that does this logic that I showed? Is it possible?
The structures of trigger
and function
do later.