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
Solved

Using left outer join in SQL

Posted on 2012-12-31
4
577 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
  • 2
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
EugeneZ 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 42

Expert Comment

by:EugeneZ
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

789 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