如何在mysql中进行这个查询?
从项目中选择 item_name
WHERE item_id
= $var;
我试过:
$var = 001 || 002|| 003|| 004;
$var = 001 或 002 或 003 或 004;
$var = 001 或 002 或 003 或 004;
但一切都不起作用。
谢谢,我尝试了一下,但只输出 1 个结果=> 1.
我想要的是输出全部,即 1、2、3 和 4.. 意思是,我想从 1 列中选择多个记录(行)
如何做到这一点?
SELECT item_name
from items WHERE item_id
= $var;
I tried:
$var = 001 || 002 || 003 || 004;
$var = 001 OR 002 OR 003 OR 004;
$var = 001 or 002 or 003 or 004;
But all do not work.
Thanks, i try that, but the output only 1 result => 1.
What I want is to output all, i.e. 1, 2 , 3 and 4.. Means, I want to select multiple records(rows) from 1 column
How to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果
item_id
由于某种原因是VARCHAR
:And if
item_id
is aVARCHAR
for some reason:或者您可以使用:
SELECT item_name from items WHERE item_id = 001 OR item_id = 002 等。
Or you could use:
SELECT item_name from items WHERE item_id = 001 OR item_id = 002 etc.
正确的 SQL 语法是:
the correct SQL sintax would be:
你遇到的问题比你提出的问题还要大。 您尝试编写的查询很简单,而且您对此有点迷失这一事实并不好。
如果我是你,我会退后一步并查看一些有关 sql 的教程。 在继续之前,花几个小时(或几天)学习该主题。
当然,您可以尝试“完成任务”,但您编写的查询可能会遇到严重的安全和/或性能问题。
那里有很多很好的教程。 去读读它们吧。
祝你好运!
You've got bigger problems than the question you've posed. The query you are trying to write is trivial and the fact that you are a little lost with it is not good.
If I were you, I'd take a step back and review a couple tutorials on sql. Spend a few hours (or a few days) learning the topic before proceeding.
Of course, you could just try to 'get the task done', but you will likely have significant security and/or performance issues with the queries you write.
There are a lot of good tutorials out there. Go read them.
Good luck!