如何查询包含来自包含多个外键的其他表的外键的表中的所有数据?

时间:2017-07-09 07:48:57

标签: mysql sql

以下是我的表格:
TABLE

我想在这里发生的是制定一个从tblCurrentTransaction检索所有数据的查询。

我的查询:

SELECT room_name, duration_name, price, final_price, check_in, check_out
FROM tblCurrentTransaction,
     tblRoomRates,
     tblRooms,
     tblDuration
WHERE tblRoomRates.room_id = tblRooms.id
  AND tblRoomRates.duration_id = tblDuration.id

输出:

OUTPUT

它会打印出其他表格中的所有内容。
我想要它只是在tblCurrentTransaction

中打印数据

1 个答案:

答案 0 :(得分:0)

我做到了:

SELECT room_name, duration_name, price, final_price, check_in, check_out
FROM tblCurrentTransaction,
     tblRoomRates,
     tblRooms,
     tblDuration
WHERE tblRoomRates.room_id = tblRooms.id
  AND tblRoomRates.duration_id = tblDuration.id
  AND tblCurrentTransaction.room_rate_id = tblRoomRates.id;