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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:26:13+00:00 2026-06-16T07:26:13+00:00

I have implemented a version control with mysql (and php). It looks like the

  • 0

I have implemented a version control with mysql (and php).

It looks like the following:

categories
-------------
| id | name |
|----|-------
| 1  | a
| 2  | b
| 3  | c
| 4  | d
-------------


revisions
----------------------
| id | cid | current |
|----|-----|----------
| 1  |  1  | 1       |
| 2  |  1  | NULL    |
| 3  |  2  | NULL    |
| 4  |  3  | 1       |
| 5  |  4  | NULL    |
| 6  |  4  | 1       |
----------------------

Each category has multiple revisions assigned to it. A revision is set, if “current” is set to 1 (only one revision per category can be 1, all others are NULL). What I want now is to get every category, which has new reivisions (note, once a revision is submitted it is not set to current immedeately. this is done by a e.g. a moderator). My problem is now getting also each category, which only has one revision with current IS NULL

Therefore the expected result would be:

-------------
| category.id
|------------
| 1     
| 2     
-------------

all the best

edit://

My current solution is:

SELECT categories.* FROM categories
JOIN revisions as t1 ON
(
t1.cid = categories.id
t1.current IS NULL
)
JOIN revisions as t2 ON
(
t2.id != t1.id
t2.current IS NOT NULL
t2.cid = categories.id
)
WHERE t1.id > t2.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-06-16T07:26:14+00:00Added an answer on June 16, 2026 at 7:26 am

    i made an SQL Fiddle Demo with a different table structure that will fit your needs

    CREATE TABLE `categories` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(1) NOT NULL DEFAULT '',
      `revision_id` int(11) unsigned DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    INSERT INTO categories
        (`id`, `name`, `revision_id`)
    VALUES
        (1, 'a', 1),
        (2, 'b', null),
        (3, 'c', 4),
        (4, 'd', 6),
        (5, 'e', 7),
        (6, 'f', 9)
    ;
    
    CREATE TABLE `revisions` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `category_id` int(11) unsigned NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;   
    
    INSERT INTO revisions
        (`id`, `category_id`)
    VALUES
        (1, 1),
        (2, 1),
        (3, 2),
        (4, 3),
        (5, 4),
        (6, 4),
        (7, 5),
        (8, 6),
        (9, 6)
    ;
    

    Foreign Key Relations

    ALTER TABLE `categories` 
      ADD CONSTRAINT `fk_cat_rev` 
      FOREIGN KEY (`revision_id`) 
      REFERENCES `revisions` (`id`) ON UPDATE CASCADE ON DELETE SET NULL;
    
    ALTER TABLE `revisions` 
      ADD CONSTRAINT `fk_rev_cat` 
      FOREIGN KEY (`category_id`) 
      REFERENCES `categories` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;
    

    Check Relations on DELETE

    DELETE FROM revisions WHERE id = 7;
    DELETE FROM categories WHERE id = 6;
    

    SELECT 
      cid 
    FROM (
      SELECT 
        c.id cid, 
        MAX( r.id ) mrid, 
        c.revision_id rid
      FROM 
        categories c
      JOIN 
        revisions r ON r.category_id = c.id
      GROUP BY 
        c.id ) tmp
    WHERE 
      COALESCE( mrid, 0 ) <> COALESCE( rid, 0 );
    

    SQL Fiddle DEMO

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

Sidebar

Related Questions

I have implemented Continuous Integration using TFS Version Control and TFS Build 2010. The
I would like to have your opinion about the subject version control, but focusing
I'm using emacs for almost all my work. I have also implemented version control
I have implemented my own simple version of a navigation window, mainly because navigation
I have implemented a simple entity ejb with a @version annotation. I expect that
i am using jquery version 4.x and i have implemented column chooser on my
I have implemented clean URLs using the following in my .htaccess RewriteEngine on RewriteCond
I'm currently writing a posting website that needs to have a version control on
Structured programming languages typically have a few control structures, like while , if ,
I have NEVER used ANY version control system before. I am currently using the

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.