On 3/6/08 12:09 PM, "Tim McDaniel" <[EMAIL PROTECTED]> wrote:
> On Thu, 6 Mar 2008, Dan Rogart <[EMAIL PROTECTED]> wrote:
>> 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 |
> ...
>
>> Here's how I made it work in a simple example:
>
> "mysql>" prompts removed to make it easier to copy and paste,
> and ">" quoting removed for the same reason.
>
> Dan Rogart wrote:
> create table a (id int, desc1 varchar(255));
> create table b (id int, desc2 varchar(255));
> create table c (id int, desc3 varchar(255));
> create table d (id int, desc4 varchar(255));
> insert into a values (1, 'foo');
> insert into b values (1, 'bar');
> insert into c values (1, 'fu');
> insert into d values (1, 'br');
> 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;
>
> Is that last SELECT equivalent to my version here?
>
> select a.id, a.desc1, b.desc2, c.desc3, d.desc4 from a, b, c, d
> where a.id = b.id and a.id = c.id and a.id = d.id;
>
> I mean: the two versions get the same result -- is one translated into
> the other / processed exactly the same internally? If so, um,
> my version is a little shorter.
Yep, they're the same. I think the optimizer parses them exactly the same
way too (based on how they EXPLAIN).
It's just a question of what's a more readable way for you to write joins -
with 4 tables involved, for me the query is more comprehensible at a glance
by using JOIN statements.
Your mileage may vary, of course :).
-Dan
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]