Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MaxDB - Everything about MaxDB, formerly known as SAP DB
MySQL++ - Programming with the C++ API to MySQL
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
ODBC - ODBC with the MySQL Connector/ODBC driver
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
array type

array type

2006-07-04       - By Duncan Hill

 Back
Reply:     1     2     3     4  

On Tuesday 04 July 2006 16:21, Nolan Rumble wrote:

> SELECT COUNT(*) FROM temp GROUP BY recipient;
>
> and it will list all the email addresses and how much email they
> sent/received.
>
> I suppose I can create another table which handles the variable length
> recipients but I would like to avoid that as that would make the SQL
> statements very complex and very hard to administer.

Trying to store multiple unique items in a single field is generally
considered bad normalisation.  Use linking tables, and store each e-mail
address in a separate row.

If table 1 contains an id for the mail and other unique data, table 2 contains
one recipient per row (with unique IDs per recipient (use lowercase forcing
on inserts so case differences don't matter)) and table 3 maps recipient IDs
to mail IDs:

SELECT count(*),recipient FROM table1 t1
LEFT JOIN table2 t2 ON t2.m_id=t1.m_id
LEFT JOIN table3 t3 ON t3.r_id=t2.r_id
GROUP BY recipient

Not that complex, assuming I typed it right.
--
Scanned by iCritical.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql@(protected)