Microsoft
Software
Hardware
Network
Question : help with a query
hello,
i have two tables
sms_groups and sms_group_members
CREATE TABLE `sms_groups` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`teamID` INT(10) UNSIGNED NULL DEFAULT NULL,
`description` VARCHAR(75) NULL DEFAULT NULL,
`createDate` TIMESTAMP NOT NULL,
`cellNum` VARCHAR(10) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `sg_1` (`teamID`),
INDEX `gcell` (`cellNum`)
)
CREATE TABLE `sms_group_members` (
`group_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`sms_contactID` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`group_id`, `sms_contactID`)
)
I am trying to do this query and in the query is a count of contacts in the group
this is what i initially tried but does not give correct results for a group with no members
select g.id, g.teamID, g.description, g.createDate, g.cellNum, count(*) mem_count
from sms_groups g LEFT JOIN sms_group_members m ON g.id = m.group_id
where g.teamID = 6
group by m.group_id order by g.description
I would appreciate any help
Answer : help with a query
try this
select g.id, g.teamID, g.description, g.createDate, g.cellNum, (select count(1) from sms_group_members m where g.id = m.group_id) mem_count
from sms_groups g
where g.teamID = 6
Random Solutions
Windows Update site fails to load
Somebody is sending emials form my hotmail account
Windows server 2008 NPS & AD
What is the best navigation software for a Macbook Pro and an iPhone?
Dynamic Color
Can't access Exchange 2003 OWA from Internet
How do i recover missing notes in office 2007 pro. Missing from archive folders as well.
Server Returns 404 Error when publishing through WebDAV
User can't receive emails sent to her personal email, but emails to group get through...
Binary data