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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 ================== |