SQL中同一个表中的多个INNER JOIN

时间:2014-05-27 17:57:10

标签: sql

如何从同一张表中制作多个INNER JOIN

我试过了:

SELECT * FROM ___Bookings 
INNER JOIN ___Rooms  ON ___Bookings.BOO_RoomId=___Rooms.ROO_Id 
INNER JOIN ___Kardex AS ka ON ___Bookings.BOO_ClientId=ka.___Kardex.KDX_Id 
INNER JOIN ___Kardex AS kb ON ___Bookings.BOO_BillingId=kb.___Kardex.KDX_Id 
WHERE BOO_Id=224

错误讯息:

1054 - 未知栏' ka .___ Kardex.KDX_Id'在' on子句'

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

ka.___Kardex.KDX_Id

你的意思是

ka.KDX_Id

SELECT * FROM ___Bookings 
INNER JOIN ___Rooms  ON ___Bookings.BOO_RoomId=___Rooms.ROO_Id 
INNER JOIN ___Kardex AS ka ON ___Bookings.BOO_ClientId=ka.KDX_Id 
INNER JOIN ___Kardex AS kb ON ___Bookings.BOO_BillingId=kb.KDX_Id 
WHERE BOO_Id=224