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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:02:44+00:00 2026-05-12T14:02:44+00:00

I have a table that looks like the following: id, Name, LinkBackId, Param1, Param2,

  • 0

I have a table that looks like the following:

id,  Name,     LinkBackId, Param1, Param2, Param3
1,  "Name1",   NULL,       10,     20,     30    
2,  "Name2",   NULL,       10,     20,     30 
3,  "Name3",   2,          14,     NULL,   NULL

The LinkBackId is important here because this is associated with the id that is also in this table. Looking at row 3 LinkBackId contains 2 I want it to return the row from id = 0 and merge the values from row 3 into the result like this:

3,  "Name3", 2, 10, 20, 30

I am treating the rows that contain NULL in the LinkBackId as a “master” row of parameters. The rows that contain a linkbackid are to be overriden by the master values that are not NULL.

I am wondering if there is an elegant method to do this instead of using lots of if statements.

Hope this makes sense.

Thank you

  • 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-05-12T14:02:44+00:00Added an answer on May 12, 2026 at 2:02 pm

    Here’s a query that will return the values from a row, unless it has a LinkBackId value, in which case it will use values from that row:

    SELECT 
      t1.id,
      t1.Name,
      t1.LinkBackId,
      COALESCE(t2.Param1,t1.Param1),
      COALESCE(t2.Param2,t1.Param2),
      COALESCE(t2.Param3,t1.Param3)
    FROM table t1
    LEFT OUTER JOIN table t2
      ON t1.LinkBackId = t2.id
    

    It won’t work with multiple levels of nesting (i.e. if row 2 referred back to row 1). It works by using the COALESCE function, which returns the parameter from the primary row if there are no values in the LinkBackId row.

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

Sidebar

Related Questions

I have a table that looks like the following (simplified): <table id=product_table> <tbody> <tr>
I have a categories table that looks like this: id | name | parent
I have a table that looks like this: category category_id name category_seo_friendly_url left_id right_id
I have xml that essentialy looks like the following (my actual .xml is a
I have an INSERT statement that looks like this: INSERT INTO officer (officer_number, name,
I have a table like this: Table name: PRODUCT ID PRODUCTID PRODUCTNAME 1 D100
I've just begun learning about ColdFusion ORM and persistent cfcs and how it can
I'm working on a web project. I'm using a Sql Server 20008 R2 database
I am doing a join between two tables and want to select the columns
I'm trying to replace a Keyword Analyser based Lucene.NET index with an SQL Server

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.