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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:18:41+00:00 2026-06-14T18:18:41+00:00

I have a database where everything is versioned inside itself using start_date and end_date

  • 0

I have a database where everything is versioned inside itself using start_date and end_date

What I want to do is dynamically get a version number for a row.

So, get all rows with a particular item_id ordered by start_date and then given a start_date and end_date that will isolate it down to one row. what I want is to find out where that row sits.

e.g. the data

id | item_id | start_date
1  | 1       | 01-31-2012
2  | 1       | 02-31-2012
3  | 2       | 02-31-2012
4  | 1       | 03-31-2012
5  | 2       | 05-31-2012
6  | 1       | 04-31-2012

if using select id from items where item_id = 2 and start_date = 05-31-2012

would return 5 so what I would want for the version would be 2

if using select id from items where item_id = 1 and start_date = 03-31-2012

would return 4 so what I would want for the version would be 3

The only way I can think of to do this would be to select all rows with the item_id of whatever, and then loop over each item checking the start_date, if it is not what I want increase version_number by 1.

Is there a way to do it with just mysql?

  • 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-14T18:18:42+00:00Added an answer on June 14, 2026 at 6:18 pm
    SELECT COUNT(*) version
    FROM items
    WHERE item_id = 2 AND start_date <= '2012-05-31'
    

    or id <= 5 instead of date comparison (assuming id is unique and grows monotonously)

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

Sidebar

Related Questions

Suppose I have a class Customer that is mapped to the database and everything
i have database with two values id and val so i want to ask
I have database application, I want to allow the user to restore the deleted
I have a web application working with sqlite database. My version of sqlite is
I have oracle 10.2.0.4 version..Some days before everything was well..but after changing tnsnames.ora file(I
I have version 1.6 of the MvcMiniProfiler referenced (via Nuget) and have set everything
In my app I have a dbhelper class where everything in my database happens,
I have an Access 2003 database using MS-JET linked tables (that is, there are
I want to store an HTML code in an SQL database. It stores everything
I have database with multiple tables in Microsoft SQL Server with schema in tables

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.