简体   繁体   English

使用INNER JOIN后搜索SQL查询

[英]Searching SQL query after using INNER JOIN

When displaying the table without the search it prints perfectly, when when adding the where query (which works fine in other search tables without inner join included) it produces a syntax error. 在不进行搜索的情况下显示表时,它可以完美打印,而在添加where查询(在不包含内部联接的其他搜索表中可以正常工作)时,则会产生语法错误。 Here is the code: 这是代码:

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%'

Here is a copy of the error: 这是错误的副本:

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE UserName LIKE '%zz%'' at line 4 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第4行的'WHERE UserName LIKE'%zz%'附近使用

where comes before order by order byorder by 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
WHERE UserName LIKE '%$search%'
ORDER BY UserName 

The defined order of keywords is 关键字的定义顺序为

select
from 
join
where
group by
having
order by
limit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM