'Joining MySQL table

in my database there are 2 tables : posts, room

Posts tables include ID and Title columns and includes many rooms and hotels titles and IDs.

In the room table there are 3 columns : room_id, hotel_id and price where room_id and hotel_id are from Posts table.(ID column)

I want to run a query so I can see Hotel title, Room title, room_id(ID) and price in one table.

I can't figure out the correct join command. what code should I use? thank you

MYSQL



Solution 1:[1]

Found the answer here: HOW TO JOIN SAME TABLE TWICE

Solution 2:[2]

Based on your description (if it would have featured some sample data it would have been easier) you can try this:

SELECT * FROM room r INNER JOIN posts p ON r.room_id = p.ID

Additionally I´d give matching columns similar names.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pooya
Solution 2 Martin