George
George

Reputation: 1032

MySQL Left Join to Union

I'm trying to do a left outer join to a union. The query runs, but does not display the columns from the union. What am I missing? This is my query:

SELECT p.profile_record_id, 
       p.first_name, 
       p.last_name, 
       l.entry_id, 
       l.when_logged, 
       l.amount, 
       l.reason_text 
FROM   member_profile p 
       LEFT OUTER JOIN authorize_net_log l 
                    ON ( p.profile_record_id = l.profile_record_id ) 
       LEFT OUTER JOIN (SELECT assigned_entry_number, 
                               payment_status AS e_status, 
                               'vehicle'      AS type, 
                               profile_record_id 
                        FROM   event_entry 
                        UNION 
                        SELECT '', 
                               co_payment_status, 
                               'driver', 
                               profile_record_id 
                        FROM   event_co_driver) u 
                    ON ( p.profile_record_id = u.profile_record_id ) 
WHERE  l.response_code = '1' 
       AND l.reason_code = '1' 

Upvotes: 1

Views: 844

Answers (1)

Quassnoi
Quassnoi

Reputation: 425391

You probably should add them to the SELECT list:

SELECT  u.*, p.profile_record_id, p.first_name, p.last_name, l.entry_id, l.when_logged, l.amount, l.reason_text
FROM    ...

Upvotes: 2

Related Questions