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 8383505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:10:45+00:00 2026-06-09T17:10:45+00:00

I have the following data in a mapping table: ID1 LOCALID ID2 Local_-1 BankA_7-9

  • 0

I have the following data in a mapping table:

ID1         LOCALID         ID2
Local_-1    BankA_7-9       Local_2647
Local_0     Bank_7-9        Local_2647
Local_2624  BGROMF          NULL
Local_2619  BIS             NULL

ID2 is nullable.

My second table looks like:

ID1        ID2
Local_-1   Local_2674 
Local_0    Local_2674
Local_2624 Local_2674
Local_2619 Local_2674

How do I inner join the tables with the following condition? Is it possible to do this without an if statement?

If ID2 in the mapping table is null just join on ID1 otherwise join on ID1 and ID2.

My starting point (which will obviously exclude the null values) is:

SELECT * FROM 
    #Table2 C
     INNER JOIN Mapping F 
                  ON C.ID1 = F.ID1 AND
                  C.ID2 = F.ID2
  • 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-09T17:10:47+00:00Added an answer on June 9, 2026 at 5:10 pm
    SELECT * FROM  
        #Table2 C 
         INNER JOIN Mapping F  
                      ON C.ID1 = F.ID1 AND 
                      C.ID2 = ISNULL(F.ID2, C.ID2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following mapping: <hibernate-mapping package=server.modules.stats.data> <class name=User table=user> <id name=id> <generator class=native></generator>
I have the following data structure (it's an append only table for mapping content
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
I have following data in excel table r1 r2 r3 r4 r5 v1 v2
I have a SQL table (Trade Mapping) with the following columns: BTF_TRADE_MAPPING_KEY int BTF_SYSTEM_CODE
I have the following two entities with a bi-directional OneToOne relational mapping, data access
I have following data frames > head(elo) date elo 1 1921-12-18 1597 2 1922-05-14
I have following data structure (simplified): A giant list of the class TestClass public
I have following data to save in database using php my data is :
I have following data in a file called binFile 78 1 79 4 80

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.