MySQL无法使用SELECT IN检索重复的行
我无法使用SELECT IN检索ID重复的行 ID列是自动递增的主键MySQL无法使用SELECT IN检索重复的行,mysql,Mysql,我无法使用SELECT IN检索ID重复的行 ID列是自动递增的主键 SELECT ID FROM dbproduct WHERE ID IN (3,2,1,4,3,2,1,4); 我得到了下面的结果 除此之外,它似乎没有按发送顺序显示结果 我正在寻找一个查询,以获得所需的结果是这样的吗 cpsrvd 11.86.0.27 数据库客户端版本:libmysql-5.6.43 PHP版本:7.3.6您可以先将这些数字放入派生表中(以及它们在列表中的顺序),然后加入: select p.* from
SELECT ID FROM dbproduct WHERE ID IN (3,2,1,4,3,2,1,4);
我得到了下面的结果
除此之外,它似乎没有按发送顺序显示结果
我正在寻找一个查询,以获得所需的结果是这样的吗
cpsrvd 11.86.0.27
数据库客户端版本:libmysql-5.6.43
PHP版本:7.3.6您可以先将这些数字放入派生表中(以及它们在列表中的顺序),然后加入:
select p.*
from (
select 3 id, 1 seq
union all select 1, 2
union all select 1, 3
union all select 4, 4
union all select 3, 5
union all select 2, 6
union all select 1, 7
union all select 4, 8
) n
inner join dbproduct p on p.id = n.id
order by n.seq
您可以将mysql更新到8.0.21版。这是工作
不幸的是,这是一个共享主机,我无法更改mysql版本。mysql版本8.0.21-0ubuntu0.20.04.4,适用于x86_64((Ubuntu))上的Linux
ID
-----
3
2
1
4
3
2
1
4
------
select p.*
from (
select 3 id, 1 seq
union all select 1, 2
union all select 1, 3
union all select 4, 4
union all select 3, 5
union all select 2, 6
union all select 1, 7
union all select 4, 8
) n
inner join dbproduct p on p.id = n.id
order by n.seq