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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:19:01+00:00 2026-05-29T12:19:01+00:00

I have the following tables (this is abbreviated) tableAssignments id timestamp // updated when

  • 0

I have the following tables (this is abbreviated)

tableAssignments
    id
    timestamp             // updated when row is modified
    tableSystems
    tableUsers
    ...

tableAssignmentsSnapshot
    id
    timestamp             // set when row created, snapshots never change
    tableSystemsSnapshot
    tableUsersSnapshot
    tableAssignments_id   // reference to "tableAssignments" row this was created from
    syncKey               // Changed when snapshots are created, max value is latest

Sometime after the tableAssignments are changed, snapshots of all the assignments are taken and the snapshots are created with the same syncKey. I am trying to write a query to check if the latest “tableAssignmentsSnapshot” are up to date or if new ones should be taken. The logic required is:

  1. Determine the latest tableAssignmentSnapshots for each system, which is determine by maximum syncKey (see query below).

  2. Join the result from #1 with tableAssignments.

  3. If timestamp from tableAssignments > timestamp from tableAssignmentsSnapshot then new snapshot is required.

The following query accomplishes step #1 and runs fast. It returns the tableAssignmentSnapshots with the greatest value of “syncKey” for each system.

select * from
    tableAssignmentsSnapshot d inner join tableSystemsSnapshot e
    on d.systemId = e.id
    where d.syncKey = (select MAX(syncKey) from tableAssignmentsSnapshot y inner join tableSystemsSnapshot z
  on y.systemId = z.id
   where tableSystems_id = e.tableSystems_id)

I’m struggling with what to do next. I need to be able to do something like the following but am having trouble with the syntax required:

select * from tableAssignments a right outer join
(
    the result from above query
)
on a.id = ?.tableAssignments_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-05-29T12:19:02+00:00Added an answer on May 29, 2026 at 12:19 pm

    You could wrap your first query on a CTE:

    ;WITH CTE AS
    (
        SELECT * -- Here you should list only the columns that you are gonna need
        FROM tableAssignmentsSnapshot D
        INNER JOIN tableSystemsSnapshot E
            ON D.systemId = E.id
        WHERE D.syncKey = ( select MAX(syncKey) from tableAssignmentsSnapshot y inner join tableSystemsSnapshot z
                            on y.systemId = z.id
                            where tableSystems_id = e.tableSystems_id)
    )
    
    SELECT * 
    FROM tableAssignments A
    RIGHT JOIN CTE B
    ON A.id = B.tableAssignments_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following row in my table: course_data: user_id days <-- This
Having a mental block with going around this query. I have the following tables:
I have the following 4 tables (simplified for this question): Company CompanyId | Name
I have the following two tables (simplified for this question): CREATE TABLE team (
I have some trouble with this. I have one database with the following tables:
ok this is hard to explain... i have the following tables: table : words
I have following table structure, with many tables like this: data_1: +-------+--------+-------+ | views
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
I have the following tweets table: tweet_id user_id text --------------------------------------------------- 1 2 this is
I have the following function. $(function() { $(.sectionHeader:gt(0)).click(function() { $(this).next(.fieldset).slideToggle(fast); }); $(img[alt='minimize']).click(function(e) { $(this).closest(table).next(.fieldset).slideUp(fast);

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.