Fetch rows and the COUNT of qualifying related rows within the same table using CodeIgniter
I have a table, where I need to get the contacts from. So I use a complex query to retrieve all the contacts from my "sms" table. However, it should only count the records for the provided "imei" field, but my query keeps returning all the counts for the specific contact. Below is the code is use: $sql = $this->db->query(' SELECT t1.mnumber AS t1_number, t1.mcontent AS t1_content, t1.mcontact as t1_contact, SUM(t2.TOTAL) AS mTotal FROM sms t1 JOIN (SELECT mContent, mcontact, COUNT(mNumber) AS TOTAL, mnumber, MAX(mID) mID FROM sms GROUP BY mContact) t2 ON t1.mcontact = t2.mcontact AND t1.mid =
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.