SELECT u.id AS pid ,
b2.id AS id ,
b2.message AS MESSAGE,
b2.uid AS uid,
b2.date AS DATE
FROM (
(SELECT b.id AS id ,
b.pid AS pid ,
b.message AS MESSAGE,
b.uid AS uid,
b.date AS DATE
FROM wall_posts AS b
JOIN Friends AS f
ON f.id = b.pid
WHERE f.buddy_id = '1'
AND f.status = 'b'
ORDER BY DATE DESC
LIMIT 0, 10
)
UNION
(SELECT id ,
pid ,
MESSAGE,
uid,
DATE
FROM wall_posts
WHERE pid = '1'
ORDER BY DATE DESC
LIMIT 0, 10
)
) AS b2
JOIN Users AS u
ON b2.pid = u.id
WHERE u.banned ='0'
AND u.email_activated='1'
ORDER BY DATE DESC
LIMIT 0, 10
是代碼。不知道我怎麼會得到這個帖子。平時我知道我會做select count(*) as num
我試圖從聯合mysql查詢獲得帖子的數量?
所以我做了什麼我把
SELECT u.id AS pid ,
b2.id AS id ,
b2.message AS MESSAGE,
b2.uid AS uid,
b2.date AS DATE
FROM
,並把它改成
SELECT COUNT(u.id AS pid ,
b2.id AS id ,
b2.message AS MESSAGE,
b2.uid AS uid,
b2.date AS DATE) as num
FROM
,並沒有類似的東西所有的select語句,清楚,沒有工作,不斷得到錯誤,如#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS pid , b2.id AS id , b2.message AS MESSAGE, b' at line 1
。那麼我怎麼會得到伯爵呢?我需要計數我的分頁php類。
Nvm,我剛剛發現mysql_num_rows同時做。 – Keverw 2010-10-16 00:46:53