Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Select - Combine COUNT with GROUP_CONCAT
    primarykey
    data
    text
    <p>I currently have a MySQL SELECT statement that pulls information from two tables to display a "Sent Messages" field for private messaging. </p> <p>I'd like to know how I can do add a COUNT to my query to count the number of "receivers" in one thread.</p> <p>Here's the basic gist of my table structure, (NOTE: the relational tie between the two tables is the 'message-id' in pm-info and the "id" in pm_data):</p> <pre><code>pm_info: id message_id receiver_id is_read read_date pm_data: id date_sent title sender_id thread_id content </code></pre> <p>Here's my SELECT Statement:</p> <pre><code>SELECT pm_info.is_read, group_concat(DISTINCT receiver.usrFirst) as receiver_name, pm_data.date_sent, pm_data.title, pm_data.thread_id, pm_data.id as data_id, MAX(date_sent) AS thread_max_date_sent FROM pm_info INNER JOIN pm_data ON pm_info.message_id = pm_data.id INNER JOIN tblUsers AS receiver ON pm_info.receiver_id = receiver.usrID WHERE pm_data.sender_id = '$usrID' GROUP BY pm_data.thread_id ORDER BY thread_max_date_sent DESC </code></pre> <p>And it ouputs the recipients like this:</p> <pre><code>Message 1 - Recipients: John, David, Steve - thread_id = 1234 Message 2 - Recipients: Bill, David, John, Ed, Steve - thread_id = 1345 </code></pre> <p>Basically, what I'd like to do is have the option to COUNT the recipients, so in the example above, "Message 1" would display three (3) recipients, and "Message 2" would display five (5) recipients.</p> <p>This way, if I have a thread/message that was sent to 30 users, not all thirty names will be printed out.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload