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

  • Home
  • SEARCH
  • 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 8924357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:23:21+00:00 2026-06-15T07:23:21+00:00

In a setup that has several one-to-many relationships of objects, and each using a

  • 0

In a setup that has several one-to-many relationships of objects, and each using a name attribute coming from a separate table. For example

Building(BuildingName), Floor(FloorName)

If a building has 2 names (2 languageIDs) and 5 floors, where only 3 floors have names for both language IDs, I want still to have 10 resulting entries. The floor names, where they are missing when the language id is missing, being pulled(defaulted) from non-matching floor id.

  • 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-15T07:23:23+00:00Added an answer on June 15, 2026 at 7:23 am

    Is this along the right lines for what you’re after?

    Runnable example here: http://sqlfiddle.com/#!3/894e9/4

    if object_id('[FloorName]') is not null drop table [FloorName]
    if object_id('[BuildingName]') is not null drop table [BuildingName]
    if object_id('[Floor]') is not null drop table [Floor]
    if object_id('[Building]') is not null drop table [Building]
    if object_id('[Language]') is not null drop table [Language]
    
    create table [Language]
    (
        Id bigint not null identity(1,1) primary key clustered
        , code nvarchar(5)
    )
    create table [Building]
    (
        Id bigint not null identity(1,1) primary key clustered
        , something nvarchar(64)
    )
    create table [Floor]
    (
        Id bigint not null identity(1,1) primary key clustered
        , BuildingId bigint foreign key references [Building](Id)
        , something nvarchar(64)
    )
    create table [BuildingName]
    (
        Id bigint not null identity(1,1) primary key clustered
        , BuildingId bigint foreign key references [Building](Id)
        , LanguageId bigint foreign key references [Language](Id)
        , name nvarchar(64)
    )
    create table [FloorName]
    (
        Id bigint not null identity(1,1) primary key clustered
        , FloorId bigint foreign key references [Floor](Id)
        , LanguageId bigint foreign key references [Language](Id)
        , name nvarchar(64)
    )
    
    insert [Language]
          select 'en-us'
    union select 'en-gb'
    union select 'fr'
    
    insert [Building]
          select 'B1'
    union select 'B2'
    
    insert [Floor]
          select 1, 'F1.1'
    union select 1, 'F1.2'
    union select 1, 'F1.3'
    union select 1, 'F1.4'
    union select 1, 'F1.5'
    union select 2, 'F2.1'
    union select 2, 'F2.2'
    union select 2, 'F2.3'
    union select 2, 'F2.4'
    union select 2, 'F2.5'
    
    insert BuildingName
    select b.Id
    , l.id
    , 'BuildingName :: ' + b.something + ' ' + l.code
    from [Building] b
    cross join [Language] l
    where l.code in ('en-us', 'fr')
    
    insert FloorName
    select f.Id
    , l.Id
    , 'FloorName :: ' + f.something + ' ' + l.code
    from [Floor] f
    cross join [Language] l
    where f.something in ( 'F1.1', 'F1.2', 'F2.1')
    and l.code in ('en-us', 'fr')
    
    insert FloorName
    select  f.Id
    , l.Id
    , 'FloorName :: ' + f.something + ' ' + l.code
    from [Floor] f
    cross join [Language] l
    where f.something not in ( 'F1.1', 'F1.2', 'F2.1')
    and l.code in ('en-us')
    
    
    declare @defaultLanguageId bigint
    select @defaultLanguageId = id from [Language] where code = 'en-us' --default language is US English
    
    select b.Id
    , b.something
    , bn.name
    , isnull(bfn.name, bfnDefault.name)
    , bl.code BuildingLanguage
    from [Building] b
    inner join [BuildingName] bn
        on bn.BuildingId = b.Id
    inner join [Language] bl
        on bl.Id = bn.LanguageId
    inner join [Floor] bf
        on bf.BuildingId = b.Id
    left outer join [FloorName] bfn
        on bfn.FloorId = bf.Id
        and bfn.LanguageId = bl.Id
    left outer join [Language] bfl
        on bfl.Id = bfn.LanguageId
    left outer join [FloorName] bfnDefault
        on bfnDefault.FloorId = bf.Id
        and bfnDefault.LanguageId = @defaultLanguageId
    

    EDIT

    This version defaults any language:

    select b.Id
    , b.something
    , bn.name
    , isnull(bfn.name, (select top 1 name from [FloorName] x where x.FloorId=bf.Id))
    , bl.code BuildingLanguage
    from [Building] b
    inner join [BuildingName] bn
        on bn.BuildingId = b.Id
    inner join [Language] bl
        on bl.Id = bn.LanguageId
    inner join [Floor] bf
        on bf.BuildingId = b.Id
    left outer join [FloorName] bfn
        on bfn.FloorId = bf.Id
        and bfn.LanguageId = bl.Id
    left outer join [Language] bfl
        on bfl.Id = bfn.LanguageId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the setup: I have several tables that hold information for data objects which
I've seen several examples of many to many relationships in EF using code-first, but
I have a setup that has a many to many relationship between customer and
I have got a field that has been setup to allow for Null, but
Hi have an ip address that has an FTP already setup on it (port
How do you handle source control setup of a non-compiled project that has dependency
I'm trying to install matplotlib on my mac setup. I find that setup.py has
I have the following setup. Class, say, Car that has a CarPart (belongsTo=[car:Car]). When
I have a package that has several components in it that would benefit greatly
I have a Spring project that uses Maven and has several profiles to allow

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.