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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:47:46+00:00 2026-05-11T10:47:46+00:00

I was given a database design which stores information about an organization and any

  • 0

I was given a database design which stores information about an organization and any changes that have happened or will happen to the organizations. Since pretty much anything can change about an organization, there is one table that only contains the unique OrganizationID’s in a table called ‘Organizations’. The changes to that organization all have an effective date and follow a similar design pattern such as the following, the location change:

Table: organization_locations  organization_id (int, not null) - Relates back to the Organizations.ID column. location_id (int, not null) - Relates to Locations.ID eff_date (datetime, not null) - The date this change becomes effective  Table: Locations  ID (int, pk, identity, not null) - ID of the location Name (varchar(255), not null) - Name of the location ... Other miscellaneous columns that aren't important for this discussion ... 

E.G. Organizations may just contain two rows which would simply hold the id’s 1 and 2 respectively. Locations may have 3 locations (id, name):

1, Location1 2, Location2 3, Location3  organization_locations (organization_id, location_id, eff_date):  1, 1, 1/1/2000  <--- Organization 1 is starting at location 1 1, 2, 1/1/2010  <--- On 1/1/2010, organization 1 moves to location 2 (from location 1) 1, 3, 1/1/2011 <--- On 1/1/2011, organization 1 moves to location 3 (in this case from location 2) 

I already have a large and possibly overly complex query for specifying a date and getting back an organizations status at that given time but I feel like there’s probably an easier way. However, the problem at hand is the following:

From this schema, how can I answer a question such as ‘What organizations will move from Location 1 to another location and what organizations will move to Location 1 from another location in the given timeframe: date1 to date2?’

A similar question that could also answer the first is: How can I query each organization’s location changes (easy) while showing the PREVIOUS location they are moving from (hard?) ?

Note: Including the LINQ tag in case there’s an easy way to do it in LINQ I can go that route.

  • 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. 2026-05-11T10:47:46+00:00Added an answer on May 11, 2026 at 10:47 am

    To Location 1:

    SELECT  DISTINCT organization_id FROM    organization_locations ol WHERE   ol.eff_date BETWEEN @date1 AND @date2         AND ol.location = 1 

    From Location 1:

    SELECT  DISTINCT organization_id FROM    (         SELECT organization_id,                (                SELECT  TOP 1 location_id                FROM    organization_locations oln                WHERE   oln.organization_id = ol.organization_id                        AND oln.eff_date < ol.eff_date                ORDER BY                        organization_id DESC, eff_date DESC                ) AS previous_location         FROM   organization_locations ol         WHERE  eff_date BETWEEN @date1 AND @date2         ) olo WHERE   previous_location = 1 

    Show previous location:

    SELECT ol.*,        (        SELECT  TOP 1 location_id        FROM    organization_locations oln        WHERE   oln.organization_id = ol.organization_id                AND oln.eff_date < ol.eff_date                AND location_id = 1        ORDER BY                organization_id DESC, eff_date DESC        ) AS previous_location FROM   organization_locations ol 

    Having a UNIQUE INDEX on (organization_id, eff_date) will help you a lot.

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

Sidebar

Ask A Question

Stats

  • Questions 176k
  • Answers 176k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I guess that the first message is required because the… May 12, 2026 at 3:15 pm
  • Editorial Team
    Editorial Team added an answer This may lead you to a couple of files: http://www.google.com/codesearch?hl=en&q=generic.h+name2+declare May 12, 2026 at 3:15 pm
  • Editorial Team
    Editorial Team added an answer There is a xml-maven-plugin that can check whether XML files… May 12, 2026 at 3:15 pm

Related Questions

I'm trying to design a database for a sports meeting. I think I've got
I have a project here that connects to an in-production database and grabs tables
We are using Linq to SQL to read and write our domain objects to
Ok, I admit it - I wrote my own view state facility for ASP.NET

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.