select all different fields but only one for the common in join

This is a discussion on select all different fields but only one for the common in join within the MySQL Database forums, part of the Database Forums category; Hi, I want to do a join for 4 tables on field "id" and "type" but ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008
avilella
 
Posts: n/a
Default select all different fields but only one for the common in join

Hi,

I want to do a join for 4 tables on field "id" and "type" but I only
want to have "id" and "type" shown once, then have all the other
fields, that are unique in the table, also shown. Something like:

select // id and type once, then all fields
from table_11 t1, table_12 t2, table_21 t3, table_22 t4
where t1.id=t2.id and
t2.id=t3.id and
t3.id=t4.id and
t1.type=t2.type and
t2.type=t3.type and
t3.type=t4.type limit 5

Any ideas?

Cheers
Reply With Quote
  #2 (permalink)  
Old 04-19-2008
Rik Wasmus
 
Posts: n/a
Default Re: select all different fields but only one for the common in join

On Sat, 19 Apr 2008 12:34:12 +0200, avilella <avilella@gmail.com> wrote:

> Hi,
>
> I want to do a join for 4 tables on field "id" and "type" but I only
> want to have "id" and "type" shown once, then have all the other
> fields, that are unique in the table, also shown. Something like:
>
> select // id and type once, then all fields
> from table_11 t1, table_12 t2, table_21 t3, table_22 t4
> where t1.id=t2.id and
> t2.id=t3.id and
> t3.id=t4.id and
> t1.type=t2.type and
> t2.type=t3.type and
> t3.type=t4.type limit 5
>
> Any ideas?


Just name them explicitly?
--
Rik Wasmus
Reply With Quote
  #3 (permalink)  
Old 04-19-2008
Paul Lautman
 
Posts: n/a
Default Re: select all different fields but only one for the common in join

Rik Wasmus wrote:
> On Sat, 19 Apr 2008 12:34:12 +0200, avilella <avilella@gmail.com>
> wrote:
>> Hi,
>>
>> I want to do a join for 4 tables on field "id" and "type" but I only
>> want to have "id" and "type" shown once, then have all the other
>> fields, that are unique in the table, also shown. Something like:
>>
>> select // id and type once, then all fields
>> from table_11 t1, table_12 t2, table_21 t3, table_22 t4
>> where t1.id=t2.id and
>> t2.id=t3.id and
>> t3.id=t4.id and
>> t1.type=t2.type and
>> t2.type=t3.type and
>> t3.type=t4.type limit 5
>>
>> Any ideas?

>
> Just name them explicitly?


As Rik said and use explicit JOINs for clarity and reliability


Reply With Quote
  #4 (permalink)  
Old 04-19-2008
Jerry Stuckle
 
Posts: n/a
Default Re: select all different fields but only one for the common in join

Rik Wasmus wrote:
> On Sat, 19 Apr 2008 12:34:12 +0200, avilella <avilella@gmail.com> wrote:
>
>> Hi,
>>
>> I want to do a join for 4 tables on field "id" and "type" but I only
>> want to have "id" and "type" shown once, then have all the other
>> fields, that are unique in the table, also shown. Something like:
>>
>> select // id and type once, then all fields
>> from table_11 t1, table_12 t2, table_21 t3, table_22 t4
>> where t1.id=t2.id and
>> t2.id=t3.id and
>> t3.id=t4.id and
>> t1.type=t2.type and
>> t2.type=t3.type and
>> t3.type=t4.type limit 5
>>
>> Any ideas?

>
> Just name them explicitly?


Which is a good practice, anyway.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0