Delete datasets with NOT highest versions and revisions












0














I want to complete the OPPOSITE of MS Access SQL: Get datasets with highest versions and revisions



I have a database table with (for this question) four columns:




  1. ID

  2. Document Number

  3. Revison

  4. Version


Each document has got 1..n Revisions and each Revision has got 1..n Versions.



What is my SQL statement for DELETING Documents where




  • either the same Document No and the same revision, but a higher version exist


  • or the same Document No and a higher revision exist (including all versions)



    ID  Doc-No Rev Vers Should be deleted?
    1 Dok1 01 01 yes, because same Doc-No higher rev exists
    2 Dok1 01 02 yes, because same Doc-No higher rev exists
    3 Dok1 01 03 yes, because same Doc-No higher rev exists
    4 Dok1 02 01 yes, because same Doc-No and a higher vers for this rev exists
    5 Dok1 02 02 no, because Rev 02 / V02 is the highest for Doc-No Dok1
    6 Dok2 01 01 yes, because same Doc-No higher rev exists
    7 Dok2 02 01 yes, because same Doc-No higher rev exists
    8 Dok2 03 01 no, because Rev 03 / V01 is the highest for Doc-No Dok2











share|improve this question





























    0














    I want to complete the OPPOSITE of MS Access SQL: Get datasets with highest versions and revisions



    I have a database table with (for this question) four columns:




    1. ID

    2. Document Number

    3. Revison

    4. Version


    Each document has got 1..n Revisions and each Revision has got 1..n Versions.



    What is my SQL statement for DELETING Documents where




    • either the same Document No and the same revision, but a higher version exist


    • or the same Document No and a higher revision exist (including all versions)



      ID  Doc-No Rev Vers Should be deleted?
      1 Dok1 01 01 yes, because same Doc-No higher rev exists
      2 Dok1 01 02 yes, because same Doc-No higher rev exists
      3 Dok1 01 03 yes, because same Doc-No higher rev exists
      4 Dok1 02 01 yes, because same Doc-No and a higher vers for this rev exists
      5 Dok1 02 02 no, because Rev 02 / V02 is the highest for Doc-No Dok1
      6 Dok2 01 01 yes, because same Doc-No higher rev exists
      7 Dok2 02 01 yes, because same Doc-No higher rev exists
      8 Dok2 03 01 no, because Rev 03 / V01 is the highest for Doc-No Dok2











    share|improve this question



























      0












      0








      0







      I want to complete the OPPOSITE of MS Access SQL: Get datasets with highest versions and revisions



      I have a database table with (for this question) four columns:




      1. ID

      2. Document Number

      3. Revison

      4. Version


      Each document has got 1..n Revisions and each Revision has got 1..n Versions.



      What is my SQL statement for DELETING Documents where




      • either the same Document No and the same revision, but a higher version exist


      • or the same Document No and a higher revision exist (including all versions)



        ID  Doc-No Rev Vers Should be deleted?
        1 Dok1 01 01 yes, because same Doc-No higher rev exists
        2 Dok1 01 02 yes, because same Doc-No higher rev exists
        3 Dok1 01 03 yes, because same Doc-No higher rev exists
        4 Dok1 02 01 yes, because same Doc-No and a higher vers for this rev exists
        5 Dok1 02 02 no, because Rev 02 / V02 is the highest for Doc-No Dok1
        6 Dok2 01 01 yes, because same Doc-No higher rev exists
        7 Dok2 02 01 yes, because same Doc-No higher rev exists
        8 Dok2 03 01 no, because Rev 03 / V01 is the highest for Doc-No Dok2











      share|improve this question















      I want to complete the OPPOSITE of MS Access SQL: Get datasets with highest versions and revisions



      I have a database table with (for this question) four columns:




      1. ID

      2. Document Number

      3. Revison

      4. Version


      Each document has got 1..n Revisions and each Revision has got 1..n Versions.



      What is my SQL statement for DELETING Documents where




      • either the same Document No and the same revision, but a higher version exist


      • or the same Document No and a higher revision exist (including all versions)



        ID  Doc-No Rev Vers Should be deleted?
        1 Dok1 01 01 yes, because same Doc-No higher rev exists
        2 Dok1 01 02 yes, because same Doc-No higher rev exists
        3 Dok1 01 03 yes, because same Doc-No higher rev exists
        4 Dok1 02 01 yes, because same Doc-No and a higher vers for this rev exists
        5 Dok1 02 02 no, because Rev 02 / V02 is the highest for Doc-No Dok1
        6 Dok2 01 01 yes, because same Doc-No higher rev exists
        7 Dok2 02 01 yes, because same Doc-No higher rev exists
        8 Dok2 03 01 no, because Rev 03 / V01 is the highest for Doc-No Dok2








      sql ms-access






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 13:33









      Flimzy

      37.1k96496




      37.1k96496










      asked Nov 22 at 13:32









      Stefan Meyer

      369414




      369414
























          3 Answers
          3






          active

          oldest

          votes


















          0














          You can do:



          delete from t
          where t.id <> (select top (1) t2.id
          from t as t2
          where t2.doc_no = t.doc_num
          order by t2.version desc, t2.revision desc, t2.id desc
          );


          Of course, back up the table before trying such a delete.






          share|improve this answer





















          • Thank you for your quick response, but I get a Syntax Error when pasting that in m y MS Access SQL-Editor. At "where t2.doc_no = t.doc_num" I assume that doc_no and doc_num has to be both "Doc_No"?
            – Stefan Meyer
            Nov 22 at 14:05












          • @StefanMeyer . . . The query should indeed be using the actual names of the the columns and tables in your database.
            – Gordon Linoff
            Nov 23 at 3:14



















          0














          The following should achieve the desired result:



          delete from Table1 t1 
          where exists
          (
          select 1 from Table1 t2
          where
          t1.[Doc-No] = t2.[Doc-No] and
          (
          t1.Rev < t2.Rev or
          (t1.Rev = t2.Rev and t1.Vers < t2.Vers)
          )
          )


          (Change Table to the name of your table along with any other fields which don't match your data)



          Always backup your data before running delete queries - there is no undo!






          share|improve this answer





























            0














            Your original top revision and top version query would be more efficient with an INNER JOIN on a couple of aggregate queries for revision and version levels rather than a correlated subquery. The former calculates once for all rows in outer query and latter for every row:



            SELECT d.*
            FROM (documents d
            INNER JOIN
            (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
            FROM documents sub_d
            GROUP BY sub_d.[Doc-No]) AS agg1
            ON d.[Doc-No] = agg1.[Doc-No]
            AND d.Rev = agg1.max_rev)

            INNER JOIN
            (SELECT sub_d.[Doc-No], sub_d.Rev,
            MAX(sub_d.Ver) AS max_ver
            FROM documents sub_d
            GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
            ON d.[Doc-No] = agg2.[Doc-No]
            AND d.Rev = agg2.rev
            AND d.Ver = agg2.max_ver


            Which translates for DELETE as:



            DELETE DISTINCTROW d.*
            FROM (documents d
            INNER JOIN
            (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
            FROM documents sub_d
            GROUP BY sub_d.[Doc-No]) AS agg1
            ON d.[Doc-No] = agg1.[Doc-No]
            AND d.Rev = agg1.max_rev)

            INNER JOIN
            (SELECT sub_d.[Doc-No], sub_d.Rev,
            MAX(sub_d.Ver) AS max_ver
            FROM documents sub_d
            GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
            ON d.[Doc-No] = agg2.[Doc-No]
            AND d.Rev = agg2.rev
            AND d.Ver = agg2.max_ver





            share|improve this answer



















            • 1




              Your first example would not returns results if an earlier revision contains a later version than that of the latest revision, e.g. Rev 1 Ver 3 and also Rev 2 Ver 2; Max(Rev) = 2, Max(Ver) = 3, but this doesn't exist.
              – Lee Mac
              Nov 22 at 22:59












            • Good point @LeeMac. Adjusted accordingly with two agg query JOIN. Thanks!
              – Parfait
              Nov 23 at 0:37











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432136%2fdelete-datasets-with-not-highest-versions-and-revisions%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can do:



            delete from t
            where t.id <> (select top (1) t2.id
            from t as t2
            where t2.doc_no = t.doc_num
            order by t2.version desc, t2.revision desc, t2.id desc
            );


            Of course, back up the table before trying such a delete.






            share|improve this answer





















            • Thank you for your quick response, but I get a Syntax Error when pasting that in m y MS Access SQL-Editor. At "where t2.doc_no = t.doc_num" I assume that doc_no and doc_num has to be both "Doc_No"?
              – Stefan Meyer
              Nov 22 at 14:05












            • @StefanMeyer . . . The query should indeed be using the actual names of the the columns and tables in your database.
              – Gordon Linoff
              Nov 23 at 3:14
















            0














            You can do:



            delete from t
            where t.id <> (select top (1) t2.id
            from t as t2
            where t2.doc_no = t.doc_num
            order by t2.version desc, t2.revision desc, t2.id desc
            );


            Of course, back up the table before trying such a delete.






            share|improve this answer





















            • Thank you for your quick response, but I get a Syntax Error when pasting that in m y MS Access SQL-Editor. At "where t2.doc_no = t.doc_num" I assume that doc_no and doc_num has to be both "Doc_No"?
              – Stefan Meyer
              Nov 22 at 14:05












            • @StefanMeyer . . . The query should indeed be using the actual names of the the columns and tables in your database.
              – Gordon Linoff
              Nov 23 at 3:14














            0












            0








            0






            You can do:



            delete from t
            where t.id <> (select top (1) t2.id
            from t as t2
            where t2.doc_no = t.doc_num
            order by t2.version desc, t2.revision desc, t2.id desc
            );


            Of course, back up the table before trying such a delete.






            share|improve this answer












            You can do:



            delete from t
            where t.id <> (select top (1) t2.id
            from t as t2
            where t2.doc_no = t.doc_num
            order by t2.version desc, t2.revision desc, t2.id desc
            );


            Of course, back up the table before trying such a delete.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 at 13:48









            Gordon Linoff

            756k35290398




            756k35290398












            • Thank you for your quick response, but I get a Syntax Error when pasting that in m y MS Access SQL-Editor. At "where t2.doc_no = t.doc_num" I assume that doc_no and doc_num has to be both "Doc_No"?
              – Stefan Meyer
              Nov 22 at 14:05












            • @StefanMeyer . . . The query should indeed be using the actual names of the the columns and tables in your database.
              – Gordon Linoff
              Nov 23 at 3:14


















            • Thank you for your quick response, but I get a Syntax Error when pasting that in m y MS Access SQL-Editor. At "where t2.doc_no = t.doc_num" I assume that doc_no and doc_num has to be both "Doc_No"?
              – Stefan Meyer
              Nov 22 at 14:05












            • @StefanMeyer . . . The query should indeed be using the actual names of the the columns and tables in your database.
              – Gordon Linoff
              Nov 23 at 3:14
















            Thank you for your quick response, but I get a Syntax Error when pasting that in m y MS Access SQL-Editor. At "where t2.doc_no = t.doc_num" I assume that doc_no and doc_num has to be both "Doc_No"?
            – Stefan Meyer
            Nov 22 at 14:05






            Thank you for your quick response, but I get a Syntax Error when pasting that in m y MS Access SQL-Editor. At "where t2.doc_no = t.doc_num" I assume that doc_no and doc_num has to be both "Doc_No"?
            – Stefan Meyer
            Nov 22 at 14:05














            @StefanMeyer . . . The query should indeed be using the actual names of the the columns and tables in your database.
            – Gordon Linoff
            Nov 23 at 3:14




            @StefanMeyer . . . The query should indeed be using the actual names of the the columns and tables in your database.
            – Gordon Linoff
            Nov 23 at 3:14













            0














            The following should achieve the desired result:



            delete from Table1 t1 
            where exists
            (
            select 1 from Table1 t2
            where
            t1.[Doc-No] = t2.[Doc-No] and
            (
            t1.Rev < t2.Rev or
            (t1.Rev = t2.Rev and t1.Vers < t2.Vers)
            )
            )


            (Change Table to the name of your table along with any other fields which don't match your data)



            Always backup your data before running delete queries - there is no undo!






            share|improve this answer


























              0














              The following should achieve the desired result:



              delete from Table1 t1 
              where exists
              (
              select 1 from Table1 t2
              where
              t1.[Doc-No] = t2.[Doc-No] and
              (
              t1.Rev < t2.Rev or
              (t1.Rev = t2.Rev and t1.Vers < t2.Vers)
              )
              )


              (Change Table to the name of your table along with any other fields which don't match your data)



              Always backup your data before running delete queries - there is no undo!






              share|improve this answer
























                0












                0








                0






                The following should achieve the desired result:



                delete from Table1 t1 
                where exists
                (
                select 1 from Table1 t2
                where
                t1.[Doc-No] = t2.[Doc-No] and
                (
                t1.Rev < t2.Rev or
                (t1.Rev = t2.Rev and t1.Vers < t2.Vers)
                )
                )


                (Change Table to the name of your table along with any other fields which don't match your data)



                Always backup your data before running delete queries - there is no undo!






                share|improve this answer












                The following should achieve the desired result:



                delete from Table1 t1 
                where exists
                (
                select 1 from Table1 t2
                where
                t1.[Doc-No] = t2.[Doc-No] and
                (
                t1.Rev < t2.Rev or
                (t1.Rev = t2.Rev and t1.Vers < t2.Vers)
                )
                )


                (Change Table to the name of your table along with any other fields which don't match your data)



                Always backup your data before running delete queries - there is no undo!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 17:33









                Lee Mac

                3,30731338




                3,30731338























                    0














                    Your original top revision and top version query would be more efficient with an INNER JOIN on a couple of aggregate queries for revision and version levels rather than a correlated subquery. The former calculates once for all rows in outer query and latter for every row:



                    SELECT d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver


                    Which translates for DELETE as:



                    DELETE DISTINCTROW d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver





                    share|improve this answer



















                    • 1




                      Your first example would not returns results if an earlier revision contains a later version than that of the latest revision, e.g. Rev 1 Ver 3 and also Rev 2 Ver 2; Max(Rev) = 2, Max(Ver) = 3, but this doesn't exist.
                      – Lee Mac
                      Nov 22 at 22:59












                    • Good point @LeeMac. Adjusted accordingly with two agg query JOIN. Thanks!
                      – Parfait
                      Nov 23 at 0:37
















                    0














                    Your original top revision and top version query would be more efficient with an INNER JOIN on a couple of aggregate queries for revision and version levels rather than a correlated subquery. The former calculates once for all rows in outer query and latter for every row:



                    SELECT d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver


                    Which translates for DELETE as:



                    DELETE DISTINCTROW d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver





                    share|improve this answer



















                    • 1




                      Your first example would not returns results if an earlier revision contains a later version than that of the latest revision, e.g. Rev 1 Ver 3 and also Rev 2 Ver 2; Max(Rev) = 2, Max(Ver) = 3, but this doesn't exist.
                      – Lee Mac
                      Nov 22 at 22:59












                    • Good point @LeeMac. Adjusted accordingly with two agg query JOIN. Thanks!
                      – Parfait
                      Nov 23 at 0:37














                    0












                    0








                    0






                    Your original top revision and top version query would be more efficient with an INNER JOIN on a couple of aggregate queries for revision and version levels rather than a correlated subquery. The former calculates once for all rows in outer query and latter for every row:



                    SELECT d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver


                    Which translates for DELETE as:



                    DELETE DISTINCTROW d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver





                    share|improve this answer














                    Your original top revision and top version query would be more efficient with an INNER JOIN on a couple of aggregate queries for revision and version levels rather than a correlated subquery. The former calculates once for all rows in outer query and latter for every row:



                    SELECT d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver


                    Which translates for DELETE as:



                    DELETE DISTINCTROW d.*
                    FROM (documents d
                    INNER JOIN
                    (SELECT sub_d.[Doc-No], MAX(sub_d.Rev) AS max_rev
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No]) AS agg1
                    ON d.[Doc-No] = agg1.[Doc-No]
                    AND d.Rev = agg1.max_rev)

                    INNER JOIN
                    (SELECT sub_d.[Doc-No], sub_d.Rev,
                    MAX(sub_d.Ver) AS max_ver
                    FROM documents sub_d
                    GROUP BY sub_d.[Doc-No], sub_d.Rev) AS agg2
                    ON d.[Doc-No] = agg2.[Doc-No]
                    AND d.Rev = agg2.rev
                    AND d.Ver = agg2.max_ver






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 23 at 0:34

























                    answered Nov 22 at 19:41









                    Parfait

                    49.3k84168




                    49.3k84168








                    • 1




                      Your first example would not returns results if an earlier revision contains a later version than that of the latest revision, e.g. Rev 1 Ver 3 and also Rev 2 Ver 2; Max(Rev) = 2, Max(Ver) = 3, but this doesn't exist.
                      – Lee Mac
                      Nov 22 at 22:59












                    • Good point @LeeMac. Adjusted accordingly with two agg query JOIN. Thanks!
                      – Parfait
                      Nov 23 at 0:37














                    • 1




                      Your first example would not returns results if an earlier revision contains a later version than that of the latest revision, e.g. Rev 1 Ver 3 and also Rev 2 Ver 2; Max(Rev) = 2, Max(Ver) = 3, but this doesn't exist.
                      – Lee Mac
                      Nov 22 at 22:59












                    • Good point @LeeMac. Adjusted accordingly with two agg query JOIN. Thanks!
                      – Parfait
                      Nov 23 at 0:37








                    1




                    1




                    Your first example would not returns results if an earlier revision contains a later version than that of the latest revision, e.g. Rev 1 Ver 3 and also Rev 2 Ver 2; Max(Rev) = 2, Max(Ver) = 3, but this doesn't exist.
                    – Lee Mac
                    Nov 22 at 22:59






                    Your first example would not returns results if an earlier revision contains a later version than that of the latest revision, e.g. Rev 1 Ver 3 and also Rev 2 Ver 2; Max(Rev) = 2, Max(Ver) = 3, but this doesn't exist.
                    – Lee Mac
                    Nov 22 at 22:59














                    Good point @LeeMac. Adjusted accordingly with two agg query JOIN. Thanks!
                    – Parfait
                    Nov 23 at 0:37




                    Good point @LeeMac. Adjusted accordingly with two agg query JOIN. Thanks!
                    – Parfait
                    Nov 23 at 0:37


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432136%2fdelete-datasets-with-not-highest-versions-and-revisions%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Berounka

                    Sphinx de Gizeh

                    Different font size/position of beamer's navigation symbols template's content depending on regular/plain...