S
S
SemihalDevs2016-11-09 19:46:42
MySQL
SemihalDevs, 2016-11-09 19:46:42

How to store the chronology of an event?

Good evening. I am faced with such a task, and I do not know how to solve it correctly:
We have 3 different tables: information about the replenishment of money, information about the withdrawal of money, information about the use of promotional codes. They all have different fields, they all have a Date field but no Description field. I need to make a chronology of events.
So, my question is: how to make this chronology?
I came up with 3 options:

  1. Generate all information with a query with subqueries/joins etc. (but is it possible and how to implement it?)
  2. Unload all tables in a PHP script and process them already there, generating the necessary information. But with large tables, you can load the database, and a request for such a script can be expensive.
  3. Make certain triggers to add a record to the database so that they place Description and Date in a pre-created table. And if necessary, do SELECT description, date FROM history?

I hope I have clearly explained my problem ... And I ask for help from experts.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Godless, 2016-11-10
@SemihalDevs

Max speaks the matter, but if the structure is not changed, do not take out such operations on the client - you will be very slow in speed.
Make a view that combines all tables with the minimum required data and sort by date.
Description is added like this:

select date, price, 'table 1' as desc from table1
UNION ALL
select date, price, 'table 2' as desc from table2
UNION ALL
select date, price, 'table 3' as desc from table3

Make a view out of it and sort it however you like

M
Max, 2016-11-09
@MaxDukov

in general, I would write this in 1 table "financial transactions", highlighting the type of event (write-off-replenishment). Promotional codes are the same account replenishment, but of a special type. But promotional codes, their "nominal value", expiration date, valid / redeemed should be stored separately
and processed in the database - unequivocally. And choose only what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question