Hi.

Without the real data, it looks like the table design could use some
normalization work: it seems there is too much data repeated in table d.

But yes, in the situation on hand, GROUP BY is a reasonable use.
Alternatively use DISTINCT, which will result in the same:

SELECT DISTINCT c.c1,c.c2,d.d2 FROM c LEFT JOIN d ON c2=d1

Btw, do you really need a LEFT JOIN (i.e. you have rows in c without
match in d)?

Bye,

        Benjamin.


PS: It would be easier to follow your example if it was not abstracted
(column and table names).


On Mon, Dec 03, 2001 at 03:25:28PM -0000, [EMAIL PROTECTED] wrote:
[...]
> This is not a problem so much as checking that I am not missing
> something obvious, before I change the way my mind deals with this type
> of situation in MySQL.
> 
> I have two tables
> 
> Table c:
> 
> +-----+-----+
> | c1  |  c2 |
> +-----+-----+
> | 1   | foo |
> | 2   | bar |
> +-----+-----+
> 
> Table d:
> 
> +-----+-----------+-------+
> | d1  |  d2       |  d3   |
> +-----+-----------+-------+
> | foo | red card  | shop1 |
> | bar | blue card | shop1 |
> | foo | red card  | shop2 |
> | bar | blue card | shop2 |
> +-----+-----------+-------+
> 
> Table d deliberately has multiple entries in d1
> 
> I want to select data from both table c and d so that I return
> 
> +-----+-----+-_---------+
> | c1  |  c2 | d2        |
> +-----+-----+-----------+
> | 1   | foo | red card  |
> | 2   | bar | blue card |
> +-----+-----+-----------+
> 
> Basically I want the all of the data from table c but need to get some
> extra info e.g. descriptions from table d.
> 
> Using:
> 
> SELECT c.c1,c.c2,d.d2 FROM c LEFT JOIN d ON c2=d1
> 
[...]
> I can GROUP BY c.c1 (unique row number) to return the results I want but
> I am not sure if this is the intended/best way to get this result.
> 
[...]



-- 
[EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to