tbl_group
( group_id
, user_id
, group_name
, group_image
, group_description
, doi
)
(9, 28, 'bbb', '1339660354imagesv.jpg', 'dfdsfsdf', '2012-06-14 13:22:34'),
(11, 1, 'cccc', '', '', '2012-06-14 14:49:56'),
(22, 1, '000', '', '', '2012-06-14 15:31:43');
tbl_groupnews
news_id
, user_id
, group_id
, group_news
,doi
(1, 1, 22, 'hi \n', '2012-06-14 16:20:36'),
(2, 1, 22, 'hello', '2012-06-14 16:21:59'),
(3, 1, 22, '1111', '2012-06-14 16:25:13'),
(4, 1, 22, 'jj', '2012-06-14 16:34:41'),
(5, 28, 9, 'hi', '2012-06-15 09:48:47');
tbl_groupmembers
groupmember_id
, group_id
, adder
, member
,doi
(1, 9, 28, 1, '2012-06-14 13:22:35'),
(2, 9, 28, 66, '2012-06-14 13:22:35'),
(4, 11, 1, 2, '2012-06-14 14:49:56'),
(5, 11, 1, 28, '2012-06-14 14:49:56'),
(6, 11, 1, 62, '2012-06-14 14:49:56'),
(36, 22, 1, 28, '2012-06-14 16:15:41'),
(37, 22, 1, 62, '2012-06-14 16:16:55'),
(38, 22, 1, 66, '2012-06-14 16:18:35'),
(39, 22, 1, 70, '2012-06-14 16:19:33');
我运行查询
SELECT tbl_groups.*,
COUNT (tbl_groupnews.news_id) AS cn1,
COUNT (tbl_groupmembers.group_id) AS cn2
FROM tbl_groups
LEFT JOIN tbl_groupnews ON tbl_groups.group_id = tbl_groupnews.group_id
LEFT JOIN tbl_groupmembers ON tbl_groupmembers.group_id = tbl_groups.group_id
WHERE (tbl_groups.user_id = 28 OR tbl_groupmembers.member = 28)
GROUP BY tbl_groups.group_id
我的要求是我需要从 group、count of news 和 count of members 中获取所有值WHERE user_id = 28 or member id = 28
。
谁能帮我找到解决方案?