在 MYSQL 的子查询中使用 LIMIT 关键字的替代方法
我有一个包含以下列的表 TEST:
I have a table TEST with the following columns :
code_ver (VARCHAR)
suite (VARCHAR)
date (DATE)
现在我想选择具有不同值 code_ver & 的 10 行code_ver NOT LIKE '%DevBld%' 按日期降序排序.
Now I want to select 10 rows with a distinct value of code_ver & code_ver NOT LIKE '%DevBld%' sorted by date desc.
所以我写了以下查询:
select *
from test
where code_ver IN (select DISTINCT code_ver
from test
where code_ver NOT LIKE '%DevBld%'
ORDER by date DESC LIMIT 10);
这个查询应该可以正常工作,但我的 MySQL 版本说:
This query should ideally work, but my version of MySQL says :
此版本的 MySQL 尚不支持 'LIMIT &在/所有/任何/一些子查询'
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
有人可以建议我替代此查询吗?
Can someone suggest me an alternative to this query?
推荐答案
你得到的错误并不完全是因为 MySQL 的版本.我认为所有版本都支持.您必须更改 LIMIT 10 位置并将其放在)"之后.请让我知道这对你有没有用.我在我的上运行了波纹管,它工作正常.
The error you are getting is not exactly because of the version of MySQL. I think all versions support that. You have to change the LIMIT 10 place and place it after ")". Let me know if it works for you. I ran the bellow one on mine and it works.
例如
SELECT * FROM test where name IN (
SELECT DISTINCT name
FROM projects
WHERE name NOT LIKE "%DevBld%"
ORDER by date_created DESC
) LIMIT 10;
更新:试试下面的一个,这样顺序就行了:
Update: Try the one below, this way order would work:
SELECT * FROM automation.e2e_projects WHERE name IN (
SELECT DISTINCT name
FROM automation.e2e_projects
WHERE name NOT LIKE "%DevBld%"
) ORDER by date_created DESC LIMIT 10;
相关文章