我必须从2个表中获取有限表的数据我正在使用此查询,并面临一个错误This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery

   SELECT S.* FROM softwares S
   WHERE S.SoftId IN (
     SELECT V.* FROM versions as V
     WHERE V.SoftId = S.SoftId
     ORDER BY DateAdded DESC LIMIT 1
   ) LIMIT 5

我必须从Softwars.SoftId=Versions.SoftId的版本和软件中选择所有列,并从表版本中选择最新版本。
谢谢

最佳答案

SELECT s.*,v.*
FROM softwares s LEFT JOIN versions v ON s.SoftId = v.SoftId
WHERE DateAdded IS NULL
    OR DateAdded = (
        SELECT MAX(DateAdded)
        FROM versions v2
        WHERE v2.SoftId = s.SoftId
    )

https://www.db-fiddle.com/f/bNYJL5eobFYP3TRukA1Wi7/0

关于php - 此版本的MySQL尚不支持'LIMIT&IN/ALL/ANY/SOME子查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51938960/

10-13 03:41