我正在尝试使用包含SELECT
(如下)的WHERE IN
来LIMIT
,这显然不受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)
但是我想要执行此操作而不必运行第一条语句,将值复制并粘贴到第二条中然后重新运行。
答案 0 :(得分:2)
您可以在此处使用Derived Table。根据您在子查询(派生表)中的条件获取uid
和old_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