如何在 MySQL 中多次使用空变量?
我正在尝试检查 MySQL 语句中是否有 2 个空变量,但我似乎可以得到非常正确的语法。这是我现在所拥有的,它一直给我一个错误。谁能告诉我如何正确地做到这一点?
SELECT threads, userid, username, usergroupid
FROM " . TABLE_PREFIX . "user
WHERE
" . iif(!empty($exuserids), "AND userid NOT IN ($exuserids)") . "
" . iif(!empty($exgroups), "AND usergroupid NOT IN ($exgroups)") . "
ORDER BY threads DESC
LIMIT 1
I am trying to check for 2 empty variables in a MySQL statement but I can seem to get the syntax quite right for it. Here is what I have now and it keeps giving me an error. Can anyone please tell me how I can do this properly?
SELECT threads, userid, username, usergroupid
FROM " . TABLE_PREFIX . "user
WHERE
" . iif(!empty($exuserids), "AND userid NOT IN ($exuserids)") . "
" . iif(!empty($exgroups), "AND usergroupid NOT IN ($exgroups)") . "
ORDER BY threads DESC
LIMIT 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
使用:
在指定“AND ...”之前需要有一个 WHERE 子句 -
1 = 1
将被优化掉。这是动态 SQL 中使用的一个技巧,可以使 WHERE 子句连接更容易。Use:
There needs to be a WHERE clause before you specify "AND ..." - the
1 = 1
will be optimized out. It's a trick used for dynamic SQL to make WHERE clause concatenation easier.