I have mysql table
region_id | name | parent_id
1 | Österreich | 0
3 | Deutschland | 0
4 | Bayern | 3
5 | Bad Griesbach| 4
6 | Nordrhein-Westfalen| 3
7 | Île-de-France | 7
....
I write the query
SELECT
h.hotel_id,
h.hotel_name,
t1.region_id,
t1.name AS name1,
t2.region_id,
t2.name AS name2,
t3.region_id,
t3.name AS name3
FROM
hotel_service.hotel h
LEFT JOIN region_service.region t1 ON t1.region_id = h.region_id
LEFT JOIN region_service.region t2 ON t2.region_id = t1.parent_id
LEFT JOIN region_service.region t3 ON t3.region_id = t2.parent_id
WHERE
hotel_id IN ('10640' , '10003', '10004', '10005', '10007')
and result like this
hotel_id hotel_name city_id name1 region_id name2 region_id name3
10003 Dorfhotel 231 Sylt 30 Schleswig 3 Deutschland
10004 Iberotel 22 Boltenhagen 21 Mecklenburg 3 Deutschland
10005 Hotel 170 Barcelona 169 Katalonien 168 Spanien
10007 Schlosshotel 175 Rügen 21 Mecklenburg 3 Deutschland
10640 Hotel Berlin 36 Berlin 3 Deutschland
but the problem in order of result for example hotel_id 10640 - 3 Deutschland
shows in wrong column, its should show on last column because last column is for country
.