E
E
Evgeny Ivanov2022-04-16 13:45:19
MySQL
Evgeny Ivanov, 2022-04-16 13:45:19

What is the best way to organize work with 3 tables?

There are 3 tables - Addresses, People, Documents, storing records of addresses, people and documents (your KO).
Each table has a unique field (key) and other fields.

The logic of the tables is as follows:
Each address can correspond to one or more people.
Each address can correspond to one or more documents.
Simply put:
Ivanov lives at Lenin
's address Petrov lives
at Zhukov's address Bashkirov lives at Zhukov's address
//
Document 1 is located at Lenin
's address Document 2
is located at Zhukov's address Document 3 is located at Zhukov's address

Similarly with people and documents.
Ivanov lives at Lenin's address (it was already higher)
Ivanov owns document 1.
and so on.
Each object (Address, person, document) can own one or more other objects.

Question such - as it is better to organize work with such 3 tables? Samples, etc.
For example: display all people who own document 1 and document 2.

Join only? Or does it make sense to create an intermediate table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N, 2022-04-16
@Fernus

Main tables:
- users;
- documents;
- addresses.
Linked tables:
- user_address (user_id, address_id);
- user_document (user_id, document_id);
- document_address (document_id, address_id).
Build queries using JOIN ...the most classic option...
UPD:
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question