Answer the question
In order to leave comments, you need to log in
How to join multiple tables?
Good day. Previously, I had minimal contact with join and I ask you to tell me how to make such a request or change the architecture.
there is a table regions
id, name
1, Moscow
2, St. Petersburg
3, Saratov
table cities
id, parentid, name
10, 1, Reutov
11, 2, Shushary
12, 3, Engels
and, accordingly, a table with my data
id data, location, name
1, 1, Ivan
2, 3, Stepan
3
, 11, Peter
Those. At the exit, get
1, Moscow, Ivan
2, St. Petersburg, Stepan
3, Shushary, Petr
thanks in advance for the replies
Answer the question
In order to leave comments, you need to log in
SELECT * FROM appusers a LEFT JOIN city c ON a.city = c.id_city LEFT JOIN country cntry ON c.id_country = cntry.id_country
Don't forget to make clear names for your tables. Region(RegionID, Name); city(CityID, RegionID, CityName) etc. to make it clear what is foreignkey and what is not.
Location where these numbers come from, what is it? Region? City? I understand I want to be shorter, but then there are more problems. Especially for people who can work with it in the future. And Berdiev has already given a good example)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question