此版本的MariaDB尚不支持“ LIMIT&IN / ALL / ANY / SOME子查询”-多个WHERE和LIMITS

时间:2019-07-12 11:52:05

标签: mysql mariadb

我正在尝试使用包含SELECT(如下)的WHERE INLIMIT,这显然不受MariaDB支持:

This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

我在这里查看了推荐使用INNER JOIN的其他解决方案,但是这些示例不起作用,因为我有两个WHERE查询,两个查询都包含一个LIMIT < / p>

SELECT * FROM table1
WHERE uuid IN (
  SELECT uid FROM table1
  WHERE updated_at LIKE '2019-07-12 08%'
  AND player_id IS NOT NULL
  LIMIT 1
)
OR uuid IN (
  SELECT old_uuid FROM table1
  WHERE updated_at LIKE '2019-07-12 08%'
  AND player_id IS NOT NULL
  LIMIT 1
)

结果应与这样做相同:

SELECT uuid, old_uuid FROM table1
WHERE updated_at LIKE '2019-07-12 08%'
AND player_id IS NOT NULL
LIMIT 1

获取两个值,然后将它们插入:

SELECT * FROM table1
WHERE uuid LIKE *VALUE1* --(uuid from above)
OR uuid LIKE *VALUE2* --(old_uuid from above)

但是我想要执行此操作而不必运行第一条语句,将值复制并粘贴到第二条中然后重新运行。

1 个答案:

答案 0 :(得分:2)

您可以在此处使用Derived Table。根据您在子查询(派生表)中的条件获取uidold_uuid;然后JOIN到主表,将其中一个与uuid匹配:

SELECT 
  t1.*
FROM 
  table1 AS t1 
JOIN 
(
  SELECT uid, old_uuid 
  FROM table1
  WHERE updated_at LIKE '2019-07-12 08%'
    AND player_id IS NOT NULL
  LIMIT 1
) AS dt ON dt.uid = t1.uuid 
           OR dt.old_uuid = t1.uuid