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 166253

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:03:55+00:00 2026-05-11T12:03:55+00:00

I have the following tables within a database, that I am using to store

  • 0

I have the following tables within a database, that I am using to store the results of surveys:

alt text

Each time I speak to someone at a store (read Shop), I create a new transaction, with a date/time (tblTransaction.Created). Each transaction can have many question answers associated with it.

My problem is that 2 transactions could both contain different answers to the same question and I am trying to create an SQL query/procedure to return only the latest question answers for a given store.

Here’s an example:

I speak with someone at Some Shop Plc. and create a transaction on the 01/01/09 (transaction ID 1). In this transaction, I ask QuestionIDs 1 and 2. Then on the 10/01/09 I speak to them again, creating a new transaction (transaction ID 2) and answer questions 2 and 3.

I want to be able to show the list of latest answers; Question 1 from the first transaction and questions 2 and 3 from the second transaction.

  • 0 0 Answers
  • 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-11T12:03:56+00:00Added an answer on May 11, 2026 at 12:03 pm
    SELECT      S.StoreID,      S.BranchName,      A.QuestionID,      T.Created,      A.* FROM      tblStore S INNER JOIN tblTransaction T ON      T.StoreID = S.StoreID INNER JOIN tblAnswer A ON      A.TransactionID = T.TransactionID AND      A.StoreID = S.StoreID WHERE NOT EXISTS           (           SELECT                T2.StoreID,                A2.QuestionID,                T2.TransactionID,                T2.CreatedDate           FROM                tblTransaction T2           INNER JOIN tblAnswer A2 ON                A2.TransactionID = T2.TransactionID AND                A2.StoreID = T2.StoreID           WHERE                T2.StoreID = T.StoreID AND                A2.QuestionID = A.QuestionID AND                T2.CreatedDate > T.CreatedDate           ) 

    You can also do this by LEFT OUTER JOINing the subquery on the same criteria as in the WHERE clause and looking for a NULL value in it or you can remove the TransactionID from the subquery use a MAX() on the CreatedDate and look for a match that way with an INNER JOIN.

    Keep in mind that this may not act how you are expecting if you have multiple transactions for the same store with the same created date. You may need to add an additional criteria there based on your business rules around that situation.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are using the MVC paradigm, the controller should… May 11, 2026 at 7:45 pm
  • Editorial Team
    Editorial Team added an answer This works for me. Hope this helps! private static ISessionFactory… May 11, 2026 at 7:45 pm
  • Editorial Team
    Editorial Team added an answer In the SDK directory is a program called MageUI.exe. This… May 11, 2026 at 7:45 pm

Related Questions

I would like to confirm that the following analysis is correct: I am building
I have a report that I created with Crystal Reports 2008. This report uses
I don't know much about database optimization, but I'm trying to understand this case.
My current development project has two aspects to it. First, there is a public

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.