Click here to Skip to main content
14,393,196 members
Rate this:
Please Sign up or sign in to vote.
See more:
tbl_message(message_id, subject, content, category)
tbl_log_message(log_id, msg_id, sent_by, sent_on, status)


log_id ... msg_id ... sent_to ...... sent_by ... sent_on ... status
1............5......abc1@gmail.com...admin@gmail.com... 15-10-2014... Draft
2............5......abc2@gmail.com...admin@gmail.com... 15-10-2014... Draft
3............5......abc3@gmail.com...admin@gmail.com... 15-10-2014... Pending
4............5......abc4@gmail.com...admin@gmail.com... 15-10-2014... Delivered
5............7......abc5@gmail.com...admin@gmail.com... 15-12-2014... Delivered
6............7......abc6@gmail.com...admin@gmail.com... 15-12-2014... Delivered
7............7......abc7@gmail.com...admin@gmail.com... 15-12-2014... Pending
8............7......abc8@gmail.com...admin@gmail.com... 15-12-2014... Pending
9............7......abc9@gmail.com...admin@gmail.com... 15-12-2014... Draft
10...........7.....abc10@gmail.com...admin@gmail.com... 15-12-2014... Failed

I want to get all emails against their status by msg id and msg subject, content also.
i have write this query,
Select COUNT(logmsg.log_id) AS TotalUsers, logmsg.log_status, msg.message_subject, msg.message_content
FROM log_messages logmsg, messages msg
WHERE logmsg.message_id = 41 and msg.message_id = 41
GROUP BY logmsg.log_status,logmsg.log_status, msg.message_subject, msg.message_content;


but i want to get list of emails also.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use Joins to get your list.

You may refer about join here:

http://www.w3schools.com/sql/sql_join_inner.asp[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

check this

Select COUNT(logmsg.log_id) AS TotalUsers, logmsg.log_status, msg.message_subject, msg.message_content
FROM log_messages logmsg 
INNER JOIN messages msg On logmsg.message_id = msg.message_id
GROUP BY logmsg.log_status,logmsg.log_status, msg.message_subject, msg.message_content;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100