我需要帮助来写一个子查询。
我有一个具有类别的文章表,其中有特色和非特色文章。
我想挑选4个特定类别的最新特色文章,这些文章不会落在前6名的最新特色文章,无论类别。这就是我所做的
select title
from node
where nid NOT IN(select nid from node order by date limit 6)
order by date
limit 4发布于 2012-09-24 20:59:01
在我的记忆中,IN()子查询还不支持LIMIT。相反,您需要对子查询执行LEFT JOIN操作,并在子查询中查找NULL:
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发布于 2012-09-24 20:56:32
假设这里有点,但你是指这样的东西吗?
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 4https://stackoverflow.com/questions/12565413
复制相似问题