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