Jump to content

Muliti Table Join


dyluck

Recommended Posts

Hi there,

 

I am creating a query that involves 3 tables total.

How would you do this query? 

 

Table 1

TID

MNAME

1

JOHN

2

JIM

 

Table 2

MNAME

FULLNAME

JOHN

JOHN HENRY

JIM

JIM JONES

 

Table 3

TID

VIEWCOUNT

1

1

1

1

2

1

 

 

I am doing 1 query that will hopfully look something like this:

SELECT * FROM TABLE 1  JOIN THE REST TO LOOK LIKE THIS:

 

JOHN HENRY    2

JIM JONES      1

 

Thanks for all your help!  The beast of a query I attempted crashed mysql server :P

Link to comment
https://forums.phpfreaks.com/topic/198826-muliti-table-join/
Share on other sites

It depends exactly what you want. If you want results regardless of whether they are in all the tables, that will be a join. Otherwise, you can do a simple query like this:

 

SELECT * FROM table1 a, table2 b, table3 c WHERE a.mname = b.mname AND a.tid = c.tid
**OR**
SELECT a.*, b.fullname, c.viewcount FROM table1 a, table2 b, table3 c WHERE a.mname = b.mname AND a.tid = c.tid

Link to comment
https://forums.phpfreaks.com/topic/198826-muliti-table-join/#findComment-1043592
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.