1
我需要帮助来编写子查询。Mysql子查询
我有一个包含精选文章和非精选文章的类别的文章表。
我想挑选4个最新的精选文章,这些精选文章不属于前6个最新的精选文章,无论其类别如何。这是我做了什么
select title
from node
where nid NOT IN(select nid from node order by date limit 6)
order by date
limit 4
我需要帮助来编写子查询。Mysql子查询
我有一个包含精选文章和非精选文章的类别的文章表。
我想挑选4个最新的精选文章,这些精选文章不属于前6个最新的精选文章,无论其类别如何。这是我做了什么
select title
from node
where nid NOT IN(select nid from node order by date limit 6)
order by date
limit 4
假设了一下这里,但你的意思是这样的吗?
select title
from node
where nid NOT IN(select nid from node where featured = 1 order by date desc limit 6)
and featured = 1
and category = ...
order by date desc
limit 4
我记得,LIMIT
尚不支持在IN()
子查询。相反,您需要针对子查询LEFT JOIN
并在子查询中查找NULL
s:
SELECT title
FROM
node
LEFT JOIN (SELECT nid FROM node ORDER BY date LIMIT 6) nids ON node.nid = nids.nid
WHERE
nids.nid IS NULL
AND node.category = 'some category'
ORDER BY date
LIMIT 4