简体   繁体   中英

Left Join not producing nulls

I have two tables like this:

website_session_id  landing_page
'1',                '/home'
'2',                '/home'
'3',                '/home'
'4',                '/home'
'5',                '/home'
'6',                '/home'
'7',                '/home'
'8',                '/home'
'9',                '/home'
'10',               '/home'



website_session_id      
'1'
'2'
'3'
'4'
'5'
'7'
'8'
'9'
'10'

I am using LEFT Join to connect both table, the website_session_id with value 6 is not shown at all.Isnt it supposed to show something like

6     /home    NULL

SQL QUERY:

SELECT 
    *
FROM
    session_first_view
        LEFT JOIN
    bounced_sessions ON session_first_view.website_session_id =  bounced_sessions.website_session_id 

在此处输入图像描述

Just check the table name: assume First Table Name is T1 and second Table is T2 the join condition is as below, wherein T1 has 2 column as mentioned

SELECT 
    *
FROM
    T1
        LEFT JOIN
    T2 ON T1.website_session_id =  T2.website_session_id 

If your first table is session_first_view it should work

http://sqlfiddle.com/#!9/81e8b06/1

Unless the first table effectively has no record with website_session_id='6'. Please check your table data.

Also, you can check if you are getting null results using

SELECT 
    *
FROM
    session_first_view
        LEFT JOIN
    bounced_sessions ON session_first_view.website_session_id =  
bounced_sessions.website_session_id 
WHERE bounced_sessions.id IS NULL

It should display at least this one with website_session_id='6'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM