我刚刚在 Oracle 中处理了一个类似的查询。在 MySQL 中这 100% 容易,因为 Oracle 没有 LIMIT 子句。这可能不是最有效的,但会为您提供所需的答案。要获取链接值,只需添加另一个联接。您可以通过删除其中一个关键字子句来搜索单个术语。
select
t1.submission_id, t1.submission_url, t1.submission_last_used , t3.keyword
from
submissions t1
join submission_keywords t2 on
t2.submission_id = t1.submission_id
join link_keywords t3 on
t3.keyword = t2.keyword
where
(t3.keyword = 'search' OR
t3.keyword = 'email')
AND t1.submission_id = (
SELECT submission_id from submissions where submission_id IN (
SELECT submission_id from submission_keywords WHERE keyword = t2.keyword)
order by submission_last_used DESC LIMIT 1);