E
E
Eldar Imamverdiyev2020-06-17 13:58:23
MySQL
Eldar Imamverdiyev, 2020-06-17 13:58:23

How to collect records from different tables in one MYSQL?

Good afternoon, I'm building a web application in one constructor. due to the lack of features out of the box, I have to poke around in phpmyadmin.
There are 4 tables. cash desk , bank , income (there is a child) , expense (there is a child) There is one more movement
table . I want all entries added to the cash register, bank, income, expense to be added to the movements with the ability to select which field "there" is equal to which field "here". It must be taken into account that the records in these four tables can be deleted, changed ... I'm too dumb to solve it myself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-06-17
@dimoff66

Look towards triggers as an example

// После добавления записи в банк
CREATE TRIGGER `cash_movemenets` AFTER INSERT ON `cash`
FOR EACH ROW BEGIN
   INSERT INTO movemenets Set date = NEW.date, income = NEW.sum;
END

// После добавления записи в кассу
CREATE TRIGGER `bank_movemenets` AFTER INSERT ON `bank`
FOR EACH ROW BEGIN
   INSERT INTO movemenets Set date = NEW.date, income = NEW.transfer;
END

NEW refers to a new record in the bank and cash tables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question