在没有搜索的情况下显示表格时,它可以完美打印,当添加where查询(在其他搜索表中没有包含内部连接时工作正常)时会产生语法错误。这是代码:
SELECT Date_entered, photo1, photo2, UserName, reserveName, species FROM Plant_Reserves
INNER JOIN Plant_Species ON Plant_Reserves.plantID = Plant_Species.plantID
INNER JOIN reserves ON Plant_Reserves.reserveID = reserves.reserveID
ORDER BY UserName WHERE UserName LIKE '%$search%'
以下是错误的副本:
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第4行'WHERE UserName LIKE'%zz%'附近使用正确的语法
答案 0 :(得分:2)
where
出现在order by
SELECT Date_entered, photo1, photo2, UserName, reserveName, species
FROM Plant_Reserves
INNER JOIN Plant_Species ON Plant_Reserves.plantID = Plant_Species.plantID
INNER JOIN reserves ON Plant_Reserves.reserveID = reserves.reserveID
WHERE UserName LIKE '%$search%'
ORDER BY UserName
关键字的定义顺序是
select
from
join
where
group by
having
order by
limit