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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:59:16+00:00 2026-06-03T02:59:16+00:00

I have a table called MapObjects which is used to store information about objects

  • 0

I have a table called MapObjects which is used to store information about objects placed on a map. I have another table called OrgLocations which is used to store all the locations where an organisation is located. Locations are defined with a latitude and longitude. Finally, I have another table called ObjectLocations which maps a map object to an organistion in the OrgLocations table. It is used to indicate a subset of the locations for an object that is shown on a map.

As an example, suppose an organisation (OrgID = 10) has 4 locations (stored in the OrgLocations table): Dallas, Atlanta, Miami, New York.
The organisation has 1 map object associated with Atlanta and Miami (MapObjects.ID = 5).

My dataset must return the records from OrgLocations that correspond with Atlanta and Miami (but not include Dallas or New York) . However, I can also have a map object that is not assigned to any location (no record in ObjectLocations). These map objects still belong to an organisation but are not associated with any specific location. In this case I want to return all the locations assigned to the organisation.

I am not sure if this is done through a conditional join or something in the WHERE clause. Here is what the tables would look like with some data:

OrgLocations

ID   OrgID     Latitude      Longitude     Name
0     10        32.780        -96.798      Dallas
1     10        33.7497       -84.394      Atlanta
2     10        25.7863       -80.2270     Miami
3     10        40.712        -74.005      New York
4     11        42.348        -83.071      Detroit

ObjectLocations

OrgLocationID      MapObjectID
1                      5
2                      5

MapObjects

ID      OrgID
5        10
6        11

In this example, when MapObjects.ID is 5, 2 locations for this object exist in ObjectLocations: Atlanta and Miami. When MapObjects.ID is 6, there is no record in ObjectLocations so all the locations in OrgLocatons that belong to the organisation (OrgID = 11) are returned.

Thanks for any help!

  • 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-03T02:59:17+00:00Added an answer on June 3, 2026 at 2:59 am

    I guess you will have the cleanest queries if you check for the existence of MapObjectID in ObjectLocations to decide what query to use.

    Something like this:

    declare @MapObjectID int
    set @MapObjectID = 5
    
    if exists(select * 
              from ObjectLocations 
              where MapObjectID = @MapObjectID)
    begin
      select *
      from OrgLocations
      where ID in (select OrgLocationID 
                   from ObjectLocations
                   where MapObjectID = @MapObjectID)
    end
    else
    begin
      select *
      from OrgLocations
      where OrgID in (select OrgID
                      from MapObjects
                      where ID = @MapObjectID)
    end
    

    As a single query.

    select OL.*
    from OrgLocations as OL
      inner join ObjectLocations as OLoc
        on OL.ID = OLoc.OrgLocationID
    where OLoc.MapObjectID = @MapObjectID
    union all
    select OL.*
    from OrgLocations as OL
      inner join MapObjects as MO
        on OL.OrgID = MO.OrgID
    where MO.ID = @MapObjectID and
          not exists (select *
                      from ObjectLocations
                      where MapObjectID = @MapObjectID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have table called Sold Products which stores buying information for product &
I have a table called Review and i want to retrieve all review objects
i have table called as Support, which have a field named Name and contains
I have a table called Stock and another called Listed, within the Stock Table
I have a table called scheduler_sched which has several columns, including a column called
I have table called page which represents every single page in my website. page_id
i have table called type which contains data family,individual i want in some pages
I have table in my SQL Server database called OrderDetail which stores the order
I have a table called BlogPost which has a 1-to-many relationship with the Comment
I have table called FinalForgotten which only contains one field called aname. The field

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.