a common SQL problem perhaps - using group by

I have a customer table and a customer_email_address table which are linked
as a customer can have multiple email addresses.

When I do a query that links the table, obviously it is possible that I
might get results with identical rows accept for the email_address field.

E.g.
select * from customer
Left join customer_email_address on (customer.id =
customer_email_address.cust_id)

As I want a list to show only one row for each customer of course I can use
groupby. Therefore adding
group by customer.id

But how do I know which row will be used when a customer has more then one
email address? Or to ask it another way, which email address will be
displayed.

Hopefully I have asked this question making it clear and simple as possible.
Thanks in advance.
cluthz [ Do, 14 Juni 2007 16:56 ] [ ID #1737659 ]

Re: a common SQL problem perhaps - using group by

On 14 Jun, 15:56, "cluthz" <WHATEEVVE... [at] by.co.uk> wrote:
| But how do I know which row will be used when a customer has more
then one
| email address? Or to ask it another way, which email address will be
| displayed.

You don't as it is explained here:
http://dev.mysql.com/tech-resources/articles/debunking-group -by-myths.html

If you have a need for a specific one of the email addresses then do
something to identifyu and select that one.

If you want the first/last newest/oldest, ... then the Strawbery Query
is your friend.
Captain Paralytic [ Do, 14 Juni 2007 17:21 ] [ ID #1737660 ]
PHP » alt.php.sql » a common SQL problem perhaps - using group by

Vorheriges Thema: MySQL3 vs MySQL 4
Nächstes Thema: MySQL - index optimisation - Any good resources?