我有一个SQL查询,它连接三个不同表中的列并且工作正常。如果Room_ID在我已经拥有的数组中,我只希望运行此查询。这两个查询分别工作正常,但我不能让它们一起工作。如果满足这个条件,这就是我想要运行的:
SELECT message.Message, message.Period, message.Date, teacher.Firstname, teacher.Lastname, rooms.Room_ID, rooms.Description
FROM message JOIN
teacher
ON teacher.Teacher_ID = message.Teacher_ID JOIN
rooms
ON message.Room_ID = rooms.Room_ID
这就是条件:
WHERE message.Room_ID IN myArray
我尝试了括号并将WHERE
条款放在不同的地方,但无济于事。
答案 0 :(得分:0)
你可以试试这个:
说,$ array是你的数组。
$sql = "SELECT message.Message, message.Period, message.Date, teacher.Firstname, teacher.Lastname, rooms.Room_ID, rooms.Description
FROM message LEFT JOIN teacher ON teacher.Teacher_ID = message.Teacher_ID LEFT JOIN rooms ON message.Room_ID = rooms.Room_ID WHERE message.Room_ID IN ".$array;
希望这有帮助。
和平!的xD
答案 1 :(得分:0)
$sql = "
SELECT message.Message, message.Period, message.Date, teacher.Firstname, teacher.Lastname, rooms.Room_ID, rooms.Description
FROM message
LEFT JOIN teacher ON teacher.Teacher_ID = message.Teacher_ID
LEFT JOIN rooms ON message.Room_ID = rooms.Room_ID
WHERE message.Room_ID IN (".implode(",", $myArray).")";