Solved

Using left outer join in SQL

Posted on 2012-12-31
4
579 Views
Last Modified: 2012-12-31
select    table1.column_id,
             table1.column_type,
             table2.column_name
from     table1
left outer join table2
on         table1.column_type = table2.column_numb

In Table 1

column_id                  column_type
1                                     NULL
2                                      NULL
3                                     300


In Table 2

table2_column_id       column_numb   column_name
1                                  100                     ABC
2                                   200                    DEf
3                                  300                     GHI


Expected value

column_id                  column_type       column_name
1                                     NULL                 NULL
2                                      NULL                NULL
3                                     300                     GHI


My query is not picking the NULL Values. What could be the reason ??
0
Comment
Question by:chokka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Eugene Z earned 500 total points
ID: 38733514
looks good for me : see test code


check your tables datatype

use test 
go
create table  Table1 (column_id   int,               column_type int)

go
insert into Table1 
select 1 ,                                    NULL
union all select 2 ,                                     NULL
union all select 3 ,                                    300

go

create table  Table2 (table2_column_id  int,      column_numb int,  column_name varchar(50))

insert into table2
select 1 ,                                 100 ,                    'ABC'
union all select 2 ,                                  200 ,                   'DEf'
union all select 3    ,                              300 ,                    'GHI'

go
select    table1.column_id,
             table1.column_type,
             table2.column_name 
from     table1
left outer join table2
on         table1.column_type = table2.column_numb

Open in new window

0
 

Author Comment

by:chokka
ID: 38733533
You say my query works fine. i actually mentioned the sample data.

i implemented same logic query in my production database, but records with null value is filtered.
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 38733592
try the example that I posted
can you post data type for the columns in your table? or table structure?
0
 

Author Comment

by:chokka
ID: 38733601
@Eugenez, Thanks !! My syntax is correct, but some conditional filtration filters the NULL Value column. Thank you for checking !!
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question