SQL找不到非空的字符串

时间:2014-03-30 20:27:28

标签: php mysql sql database syntax-error

这条线有什么问题?

$query = "SELECT * FROM orders ORDER BY id DESC LIMIT 1000 WHERE TRIM(IFNULL(email,'')) <> ''";

基本上我想从sql获取所有不是空行的电子邮件

这是我的错误讯息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE TRIM(IFNULL(email,'')) <> ''' at line 336

2 个答案:

答案 0 :(得分:3)

ORDER BY id DESC LIMIT 1000  

必须在WHERE条件

之后
$query = "SELECT * FROM 
orders WHERE 
TRIM(IFNULL(email,'')) <> '' 
ORDER BY id DESC LIMIT 1000";

答案 1 :(得分:2)

您的WHERE声明需要在FROM声明后但在ORDER BYmanual)之前声明:

SELECT * 
FROM orders 
WHERE TRIM(IFNULL(email,'')) <> '' 
ORDER BY id DESC 
LIMIT 1000";