Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:53:00+00:00 2026-06-13T16:53:00+00:00

Please refer the below script declare @table1 table ( col1 int ) declare @table2

  • 0

Please refer the below script

    declare @table1 table
    (
    col1 int
    )

    declare @table2 table
    (
    col2 int
    )

    insert into @table1 values(1)
    insert into @table1 values(2)
    insert into @table1 values(3)
    insert into @table1 values(5)
    insert into @table1 values(7)

    insert into @table2 values(1)
    insert into @table2 values(3)
    insert into @table2 values(3)
    insert into @table2 values(6)
    insert into @table2 values(4)
    insert into @table2 values(7)

Case 1:

select * from @table1 a left outer join @table2 b on a.col1=b.col2
    order by col1 

Result 1:

         col1       col2        
     -----------  ----------- 
    |    1       |    1       |
    |    2       |    NULL    |
    |    3       |    3       |
    |    3       |    3       |
    |    5       |    NULL    |
    |    7       |    7       |
    ---------------------------

Case 2:

select * from @table1 a right outer join @table2 b on a.col1=b.col2
    order by col2 

Result 2:

         col1             col2        
     -----------  ----------- 
    |    1       |    1       |
    |    3       |    3       |
    |    3       |    3       |
    |    NULL    |    4       |
    |    NULL    |    6       |
    |    7       |    7       |
    ---------------------------

Actual Case:

select * from @table1 a full outer join @table2 b on a.col1=b.col2

Actual Result:

         col1        col2        
     -----------  ----------- 
    |    1       |    1       |
    |    2       |    NULL    |
    |    3       |    3       |
    |    3       |    3       |
    |    5       |    NULL    |
    |    7       |    7       |
    |    NULL    |    6       |
    |    NULL    |    4       |
    ---------------------------

Expected Result:

         col1        col2        
     -----------  ----------- 
    |    1       |    1       |
    |    2       |    NULL    |
    |    3       |    3       |
    |    3       |    3       |
    |    NULL    |    4       |
    |    5       |    NULL    |
    |    NULL    |    6       |
    |    7       |    7       |
    ---------------------------

I tried union all with left and right join query but it doubles the result set. Is there a way that I can get this expected output.

Thanks,
Esen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:53:01+00:00Added an answer on June 13, 2026 at 4:53 pm

    You can use

    SELECT *
    FROM   @table1 a
           FULL OUTER JOIN @table2 b
             ON a.col1 = b.col2
    ORDER  BY Isnull(col1, col2) 
    

    to get your desired order. Without an ORDER BY no ordering is guaranteed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please refer to the code below. $dArr = '<script>document.write(volunteerDist);</script>'; $dArr gets the value of
Please refer to the image below - I'm not using NavigationViewController. Is there a
Please refer to this fiddle . While scrolling down, the table cells appear in
Please refer to the code below, when I comment in either of the commented
Please refer to my code below. When optimization in IAR MSP430 compiler is set
Please refer to the Java code below: class Base{ Base(){ System.out.println(Base Constructor); method(); }
please refer to my quick diagram attached below. what i'm trying to do is
I'm creating a bash script that will load CSV files using SQL*Loader. Please refer
Please refer to the below code Specialized function in non specialized Template class Is
I have an NSArray output. please refer below. I want to sort based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.