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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.