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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:19:13+00:00 2026-06-10T12:19:13+00:00

Suppose that I have 3 tables: A) Table UsrHeader —————– UsrID | UsrName —————–

  • 0

Suppose that I have 3 tables:

A) Table UsrHeader
   -----------------
   UsrID  |  UsrName
   -----------------
   1      |  Abc
   2      |  Bcd

B) Table UsrDetail
   -------------------------------
   UsrID  |  UsrLoc  | Date
   -------------------------------
   1      |  LocA    | 10 Aug 2012
   1      |  LocB    | 15 Aug 2012
   2      |  LocA    | 10 Aug 2012

C) Table Trx
   -----------------------------
   TrxID  |  TrxDate     | UsrID
   -----------------------------
   1      |  10 Aug 2012 | 1
   2      |  16 Aug 2012 | 1
   3      |  11 Aug 2012 | 2

What I want to do is to show the table like:

  ---------------------------------------
  TrxID   |  TrxDate     | UsrID | UsrLoc
  ---------------------------------------
  1       |  10 Aug 2012 | 1     | LocA
  2       |  16 Aug 2012 | 1     | LocB
  3       |  11 Aug 2012 | 2     | LocA

Notice that there is one user but different location. That’s based on the UsrDetail table that the user on a specified date has moved to another location. So, it should be show the user specific location on that date on every transaction.

I have tried this code but with no luck:

SELECT trx.TrxID, trx.TrxDate, trx.UsrID, User.UsrName, User.UsrLoc
FROM trx
INNER JOIN
( SELECT UsrHeader.UsrID, UsrHeader.UsrName, UserDetail.UsrLoc
  FROM UsrHeader
  INNER JOIN
  ( SELECT UsrDetail.UsrID, UsrDetail.UsrLoc, UsrDetail.Date
    FROM UsrDetail
  ) AS UserDetail ON UserDetail.UsrID = UsrHeader.UsrID
) AS User ON User.UsrID = trx.UsrID
             AND trx.TrxDate >= User.Date

How to do that? Thanks.

  • 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-10T12:19:14+00:00Added an answer on June 10, 2026 at 12:19 pm

    Use the following:

    SELECT trx.TrxID, trx.TrxDate, uh.UsrName, ud.UsrLoc
    FROM trx 
         INNER JOIN UsrDetail ud ON (trx.UsrId = ud.UsrId)
         INNER JOIN UsrHeader uh ON (trx.UsrId = uh.UsrId)
    WHERE ud.Date = (SELECT MAX(t.Date)
                     FROM UsrDetail t
                     WHERE t.UsrId = trx.UsrId
                       AND t.Date <= trx.TrxDate)
    

    Here’s a DEMO (SQL Fiddle).

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

Sidebar

Related Questions

Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
Suppose I have two tables, table A and table B, and that table A
Suppose I have three tables: user , group and xref , a table that
Lets suppose that I have a Category table with a column that holds the
Suppose I have table A with a field that can be either 1 or
Suppose I have two tables that are linked (one has a foreign key to
Suppose I have a table, the first column is an identity. I thought that
Suppose I have two columns in a table that represents a graph, the first
Suppose I have an array that mimics a database table. Each array element represents
Suppose I have employee and department table, employee has foreign key departmentID that is

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.