如何在mysql中进行这个查询?

发布于 2024-07-13 10:13:41 字数 344 浏览 4 评论 0原文

从项目中选择 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

樱花落人离去 2024-07-20 10:13:41
SELECT item_name from items WHERE item_id IN (1, 2, 3, 4)

如果 item_id 由于某种原因是 VARCHAR

SELECT item_name from items WHERE item_id IN ('001', '002', '003', '004')
SELECT item_name from items WHERE item_id IN (1, 2, 3, 4)

And if item_id is a VARCHAR for some reason:

SELECT item_name from items WHERE item_id IN ('001', '002', '003', '004')
暗喜 2024-07-20 10:13:41

或者您可以使用:

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.

酒绊 2024-07-20 10:13:41

正确的 SQL 语法是:

SELECT item_name from items WHERE item_id = 001 or item_id = 002 or item_id=003;

the correct SQL sintax would be:

SELECT item_name from items WHERE item_id = 001 or item_id = 002 or item_id=003;
夜还是长夜 2024-07-20 10:13:41

你遇到的问题比你提出的问题还要大。 您尝试编写的查询很简单,而且您对此有点迷失这一事实并不好。

如果我是你,我会退后一步并查看一些有关 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文