Jump to content

Three MYSQL JOINS, What Join to use?


unemployment

Recommended Posts

I have a ridiculously long query that I have created to combine three tables.  I want to combine my third table into the preexisting inner joined tables.  Ideally, the output I am looking for is that when I add the third join, I need it to not combine the rows, but rather just add in rows and order the data by datetime. 

 

How do I make it so that the data is combined, but the rows aren't smooshed together.  Do I need to use an outer join.  Let me know if you need a more concrete example.

Link to comment
https://forums.phpfreaks.com/topic/232470-three-mysql-joins-what-join-to-use/
Share on other sites

table 1 has

firstname user_id

 

table 2 has

company_id    user_id  fan_date

 

Current results generated with

 

firstname user_id fan_date

person1 3 2011-04-02 00:00:00

person2 1 2011-04-06 15:35:42

person2 1 2011-04-06 15:35:42

person2 1 2011-04-06 15:35:42

person2 1 2011-04-06 15:35:42

 

From:

 

SELECT

`users`.`firstname`,

`company_fans`.`user_id`,

`company_fans`.`fan_date`

FROM `partners`

LEFT JOIN `users`

ON `partners`.`user_id` = `users`.`id`

LEFT JOIN `company_fans`

ON `partners`.`user_id` = `company_fans`.`user_id`

 

 

But the users table doesn't have a fan_date and the fan_date doesn't go with the users table.

 

I just want the table listing to be like...

 

person1 3 null

person2 1 null

person2 1 null

person2 1 null

person2 1 null

person1 3 2011-04-02 00:00:00

person2 1 2011-04-06 15:35:42

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.