D
D
danil_linkins2018-04-11 13:56:53
MySQL
danil_linkins, 2018-04-11 13:56:53

MySQL is a one-to-many relationship. How to use?

How to work with tables with links?
I will give an example:
There is a table of brands:
+----+-----------+
| id | brand |
+----+-----------+
| 1 | bmw |
| 2 | Audi |
| 3 | Kia |
| 4 | Mercedes |
+----+-----------+
And model table:
+----+---------+----------+
| id | model | brand_id |
+----+---------+----------+
| 1 | Ceed | 3 |
| 2 | A6 | 2 |
| 3 | B class | 4 |
| 4 | class | 4 |
| 5 | Q7 | 2 |
+----+---------+----------+
Here, a one-to-many relationship is implemented, that is, several models can have one brand, on the other hand, each model has only 1 brand.
The main question here is how then to work with these tables?
That is, does it turn out that when I request a row in the model table, I will automatically receive a brand row by reference?
And most importantly, if I want to get all the models of this brand by the brand line, then how can I do this?
Because if the second table at least refers to the first, then there is no connection in the first to the second.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2018-04-11
Tag

JOIN and its varieties

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question