Ack, listen to Nanni not me.  Join order doesn't matter, now that I tested
some more :).

Off to drink more coffee,

Dan

On 3/6/08 8:45 AM, "Dan Rogart" <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> 
> On 3/6/08 8:33 AM, "roger.maynard" <[EMAIL PROTECTED]> wrote:
> 
>> I got 4 tables:
>> 
>> Table A
>> | ID  |     Description1      |
>> 
>> Table B
>> | ID  |     Description2      |
>> 
>> Table C
>> | ID  |     Description3      |
>> 
>> Table D
>> | ID  |     Description4      |
>> 
>> ALL Ids ARE COMMON Values and NONE are MISSING
>> 
>> How can I create
>> | ID  | Description 1 | Description 2 | Description 3 | Description 4 |
>> 
>>  
>> 
>> SELECT a.ID,a.Description1,b.Description2,c.Description3,d.Description4
>> FROM TableA a
>> INNER JOIN TableB b ON a.id = b.id
>> 
>> INNER JOIN TableC b ON a.id = c.id
>> 
>> INNER JOIN TableD b ON a.id = d.id
>> 
>> Doesn't give me the result
>> 
>> What am I doing wrong?
>> Can I do this?
>> 
>>  
>> 
> 
> You have to do your joins in a chain: A joins to B, B joins to C, C joins to
> D, and so on.
> 
> Here's how I made it work in a simple example:
> 
> mysql> create table a (id int, desc1 varchar(255));
> Query OK, 0 rows affected (0.13 sec)
> 
> mysql> create table b (id int, desc2 varchar(255));
> Query OK, 0 rows affected (0.00 sec)
> 
> mysql> create table c (id int, desc3 varchar(255));
> Query OK, 0 rows affected (0.07 sec)
> 
> mysql> create table d (id int, desc4 varchar(255));
> Query OK, 0 rows affected (0.00 sec)
> 
> mysql> insert into a values (1, 'foo');
> Query OK, 1 row affected (0.13 sec)
> 
> mysql> insert into b values (1, 'bar');
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into c values (1, 'fu');
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into d values (1, 'br');
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> select a.id,a.desc1,b.desc2,c.desc3,d.desc4 from a
>     -> join b on a.id = b.id
>     -> join c on b.id = c.id
>     -> join d on c.id = d.id;
> +------+-------+-------+-------+-------+
> | id   | desc1 | desc2 | desc3 | desc4 |
> +------+-------+-------+-------+-------+
> |    1 | foo   | bar   | fu    | br    |
> +------+-------+-------+-------+-------+
> 
> Hope that helps,
> 
> Dan
> 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to