a common SQL problem perhaps - using group by

a common SQL problem perhaps - using group by

am 14.06.2007 16:56:49 von cluthz

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.

Re: a common SQL problem perhaps - using group by

am 14.06.2007 17:21:11 von Captain Paralytic

On 14 Jun, 15:56, "cluthz" 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.