I have a table called email with three columns say id, emailFrom, emailTo
-------------------------------------------------- | id | emailFrom | EmailT0 | -------------------------------------------------- | 1 | A | B | -------------------------------------------------- | 2 | B | A | -------------------------------------------------- | 3 | A | B | -------------------------------------------------- | 4 | C | A | -------------------------------------------------- | 5 | B | C | -------------------------------------------------- | 6 | A | C | -------------------------------------------------- | 7 | A | B | --------------------------------------------------
now my question is , how to find out the highest conversation between two clients
i.e. A send mail to B and B send mail to A, it means they have conversation of count 2.
now,
I want to find that which users have send most emails to each other
This will return the users that have sent most emails to each other:
SELECT
LEAST(emailFrom, emailTo) email1,
GREATEST(emailFrom, emailTo) email2,
COUNT(*)
FROM
yourtable
GROUP BY
LEAST(emailFrom, emailTo),
GREATEST(emailFrom, emailTo)
ORDER BY
COUNT(*) DESC
LIMIT 1
Please see fiddle here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With