[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using left outer join in SQL

Posted on 2012-12-31
4
Medium Priority
?
590 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

656 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