brian wilson
brian wilson

Reputation: 495

Adding a JOIN to this mysql query

SELECT t1.* FROM HOSTS AS t1
WHERE
t1.BOSS = 'BRUCE'
OR ( t1.BOSS_TYPE = 'manager'
 AND t1.BOSS_ID = 'BRUCE' )
OR t1.BOSS IN ( SELECT t2.STORES FROM
  FOLLOW_STORES AS t2 
 WHERE t2.BOSSES = 'BRUCE' )

The above query works great, but i want to add a JOIN to get extra information

I want to add this JOIN but i cant get it to work. I must be inserting it in the wrong place.

 JOIN MANAGER_POSTS AS t3 ON ( t1.POSTER_ID = t3.POSTER_ID
    AND t1.SUBMISSION_TYPE =  'post' )

What is the correct way to add the join to get this extra information

Upvotes: 0

Views: 48

Answers (2)

John Woo
John Woo

Reputation: 263803

here try this one:

SELECT  t1.* , t3.*
FROM    HOSTS AS t1 
            INNER JOIN MANAGER_POSTS AS t3 
                ON ( t1.POSTER_ID = t3.POSTER_ID AND 
                     t1.SUBMISSION_TYPE =  'post' )
WHERE   t1.BOSS = 'BRUCE' 
        OR (t1.BOSS_TYPE = 'manager' AND t1.BOSS_ID = 'BRUCE' )
        OR t1.BOSS IN   ( 
                            SELECT t2.STORES 
                            FROM FOLLOW_STORES AS t2 
                            WHERE t2.BOSSES = 'BRUCE' 
                        )

Upvotes: 1

Taryn
Taryn

Reputation: 247810

You would need to add your JOIN clause after your FROM Hosts and before your WHERE

SELECT t1.* 
FROM HOSTS AS t1
INNER JOIN MANAGER_POSTS AS t3 
    ON ( t1.POSTER_ID = t3.POSTER_ID
    AND t1.SUBMISSION_TYPE =  'post' )
WHERE t1.BOSS = 'BRUCE'
    OR ( t1.BOSS_TYPE = 'manager'
          AND t1.BOSS_ID = 'BRUCE' )
    OR t1.BOSS IN ( SELECT t2.STORES 
                    FROM FOLLOW_STORES AS t2 
                    WHERE t2.BOSSES = 'BRUCE' )

Upvotes: 0

Related Questions