0
我有一個查詢返回與給定criteia匹配的數據庫表中的所有帖子,但我正在尋找一種方法,最多隻能返回5個帖子每個'post_type'
。目前查詢是選擇每一個匹配的文章,我不得不限制每個'post_type'
在PHP中的數字,這不是特別有效。在數據庫表中返回每個'post_type'的最多5個
可以這樣做嗎?謝謝。
SELECT ID, post_title, post_type
FROM wp_posts
WHERE 1=1
AND post_status = "publish"
AND (
post_type IN (
"staff"
)
AND post_name LIKE "%The%"
)
OR (
post_type NOT IN (
"staff",
"Attachment"
)
AND (
post_name LIKE "%The%"
OR post_title LIKE "%The%"
)
)
ORDER BY post_type, post_name ASC
?最近的五個?最早的五個?你可以請張貼你的模式嗎? – 2012-07-17 10:06:17