MySQL表->您可以在同一查询中多次返回同一行吗? [英] MySQL table -> Can you return the same row multiple times, in the same query?

查看:94
本文介绍了MySQL表->您可以在同一查询中多次返回同一行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT * FROM menu WHERE item_id = 1 OR item_id = 2 OR item_id = 3;

上面的语句返回3行. 但是下面的语句仅返回2行.

The above statement returns 3 rows. But the statement below only returns 2 rows.

SELECT * FROM menu WHERE item_id = 1 OR item_id = 1 OR item_id = 2;

我知道为什么会这样,但是有一种方法可以迫使item_id 1返回两次?

And I understand why like, but is there a way to force item_id 1 to be returned twice???

我想退回的物品的示例:

Example of what I want to be returned:

id-> 1筹码€2.50
id-> 1筹码€2.50
id-> 2可乐€1.60
--------------------
总计€6.60

id -> 1 Chips €2.50
id -> 1 Chips €2.50
id -> 2 Coke €1.60
--------------------
Total €6.60

推荐答案

例如,您可以加入另一个表

You could join on another table, for example

SELECT * FROM menu
INNER JOIN order_items ON menu.item_id = order_items.item_id
WHERE order_id = 123;

或者只是将它们复制到您的应用程序中.

Or just duplicate them in your application.

您实际上不需要做您所要的事情.

You shouldn't really need to do what you're asking for.

这篇关于MySQL表->您可以在同一查询中多次返回同一行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆