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
Email Marketing Reseller Solution
HP dl360 G6 Raid Driver for Windows 2008 64-bit
Info@... users Not receiving email
asp.net, c#, drop down list error
NAT on ASA to a remote server
Matching Cell Items in Excel
how to add swap partition to exsting swap in redhat linux
Globally Hide Mouse after Inactive without using constantly running Timer Interval
To Lock my pendrive
vb.net Insert comma every 3 characters