MySQL select from text column with filtering











up vote
2
down vote

favorite












I would like to query a database which is MySQL 5.



Let's say database name is db and the table name is table and the column name is column



and that column is a text



containing the following for example:



aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1


So i would like to query that table and grep only where rxp > 0918



so I'm expecting the result to be:



aksksksksjsjk&ct=100&rxp=1018&ls=1


I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'and it's working ! but that's meant that i will need to manually insert all dates !










share|improve this question







New contributor




Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    2
    down vote

    favorite












    I would like to query a database which is MySQL 5.



    Let's say database name is db and the table name is table and the column name is column



    and that column is a text



    containing the following for example:



    aksksksksjsjk&ct=100&rxp=0918&rpa=100
    aksksksksjsjk&ct=100&rxp=1018&ls=1


    So i would like to query that table and grep only where rxp > 0918



    so I'm expecting the result to be:



    aksksksksjsjk&ct=100&rxp=1018&ls=1


    I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'and it's working ! but that's meant that i will need to manually insert all dates !










    share|improve this question







    New contributor




    Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I would like to query a database which is MySQL 5.



      Let's say database name is db and the table name is table and the column name is column



      and that column is a text



      containing the following for example:



      aksksksksjsjk&ct=100&rxp=0918&rpa=100
      aksksksksjsjk&ct=100&rxp=1018&ls=1


      So i would like to query that table and grep only where rxp > 0918



      so I'm expecting the result to be:



      aksksksksjsjk&ct=100&rxp=1018&ls=1


      I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'and it's working ! but that's meant that i will need to manually insert all dates !










      share|improve this question







      New contributor




      Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I would like to query a database which is MySQL 5.



      Let's say database name is db and the table name is table and the column name is column



      and that column is a text



      containing the following for example:



      aksksksksjsjk&ct=100&rxp=0918&rpa=100
      aksksksksjsjk&ct=100&rxp=1018&ls=1


      So i would like to query that table and grep only where rxp > 0918



      so I'm expecting the result to be:



      aksksksksjsjk&ct=100&rxp=1018&ls=1


      I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'and it's working ! but that's meant that i will need to manually insert all dates !







      mysql sql regex






      share|improve this question







      New contributor




      Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 8 at 9:54









      Ike White

      111




      111




      New contributor




      Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Ike White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          Assuming that the value that comes after rxp= is always of length 4 in the format MMYY then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.



          SELECT *
          FROM db.table
          WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
          AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'


          Assuming you've got the following values under column:



          aksksksksjsjk&ct=100&rxp=0918&rpa=100
          aksksksksjsjk&ct=100&rxp=1018&ls=1
          aksksksksjsjk&ct=100&rxp=1116&ls=1


          The output of the query should be



          aksksksksjsjk&ct=100&rxp=1018&ls=1


          However, I would highly recommend you to normalise your table and store every value in a separate column (ct, rxp, rpa, ls etc.) instead of having a lot of information combined into a single string.






          share|improve this answer























          • you mentioned FROM db.table A so what is A refer to ?
            – Ike White
            Nov 8 at 10:17










          • @IkeWhite My bad. See my updated answer.
            – Giorgos Myrianthous
            Nov 8 at 10:18




















          up vote
          0
          down vote













          create table #temp(
          Integ Integer
          )
          insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
          (CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
          select * from #temp
          where Integ >918
          drop table #temp


          hope it helps you






          share|improve this answer





















            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',
            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
            });


            }
            });






            Ike White is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205251%2fmysql-select-from-text-column-with-filtering%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Assuming that the value that comes after rxp= is always of length 4 in the format MMYY then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.



            SELECT *
            FROM db.table
            WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
            AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'


            Assuming you've got the following values under column:



            aksksksksjsjk&ct=100&rxp=0918&rpa=100
            aksksksksjsjk&ct=100&rxp=1018&ls=1
            aksksksksjsjk&ct=100&rxp=1116&ls=1


            The output of the query should be



            aksksksksjsjk&ct=100&rxp=1018&ls=1


            However, I would highly recommend you to normalise your table and store every value in a separate column (ct, rxp, rpa, ls etc.) instead of having a lot of information combined into a single string.






            share|improve this answer























            • you mentioned FROM db.table A so what is A refer to ?
              – Ike White
              Nov 8 at 10:17










            • @IkeWhite My bad. See my updated answer.
              – Giorgos Myrianthous
              Nov 8 at 10:18

















            up vote
            2
            down vote













            Assuming that the value that comes after rxp= is always of length 4 in the format MMYY then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.



            SELECT *
            FROM db.table
            WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
            AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'


            Assuming you've got the following values under column:



            aksksksksjsjk&ct=100&rxp=0918&rpa=100
            aksksksksjsjk&ct=100&rxp=1018&ls=1
            aksksksksjsjk&ct=100&rxp=1116&ls=1


            The output of the query should be



            aksksksksjsjk&ct=100&rxp=1018&ls=1


            However, I would highly recommend you to normalise your table and store every value in a separate column (ct, rxp, rpa, ls etc.) instead of having a lot of information combined into a single string.






            share|improve this answer























            • you mentioned FROM db.table A so what is A refer to ?
              – Ike White
              Nov 8 at 10:17










            • @IkeWhite My bad. See my updated answer.
              – Giorgos Myrianthous
              Nov 8 at 10:18















            up vote
            2
            down vote










            up vote
            2
            down vote









            Assuming that the value that comes after rxp= is always of length 4 in the format MMYY then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.



            SELECT *
            FROM db.table
            WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
            AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'


            Assuming you've got the following values under column:



            aksksksksjsjk&ct=100&rxp=0918&rpa=100
            aksksksksjsjk&ct=100&rxp=1018&ls=1
            aksksksksjsjk&ct=100&rxp=1116&ls=1


            The output of the query should be



            aksksksksjsjk&ct=100&rxp=1018&ls=1


            However, I would highly recommend you to normalise your table and store every value in a separate column (ct, rxp, rpa, ls etc.) instead of having a lot of information combined into a single string.






            share|improve this answer














            Assuming that the value that comes after rxp= is always of length 4 in the format MMYY then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.



            SELECT *
            FROM db.table
            WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
            AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'


            Assuming you've got the following values under column:



            aksksksksjsjk&ct=100&rxp=0918&rpa=100
            aksksksksjsjk&ct=100&rxp=1018&ls=1
            aksksksksjsjk&ct=100&rxp=1116&ls=1


            The output of the query should be



            aksksksksjsjk&ct=100&rxp=1018&ls=1


            However, I would highly recommend you to normalise your table and store every value in a separate column (ct, rxp, rpa, ls etc.) instead of having a lot of information combined into a single string.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 8 at 10:26

























            answered Nov 8 at 10:14









            Giorgos Myrianthous

            3,52621233




            3,52621233












            • you mentioned FROM db.table A so what is A refer to ?
              – Ike White
              Nov 8 at 10:17










            • @IkeWhite My bad. See my updated answer.
              – Giorgos Myrianthous
              Nov 8 at 10:18




















            • you mentioned FROM db.table A so what is A refer to ?
              – Ike White
              Nov 8 at 10:17










            • @IkeWhite My bad. See my updated answer.
              – Giorgos Myrianthous
              Nov 8 at 10:18


















            you mentioned FROM db.table A so what is A refer to ?
            – Ike White
            Nov 8 at 10:17




            you mentioned FROM db.table A so what is A refer to ?
            – Ike White
            Nov 8 at 10:17












            @IkeWhite My bad. See my updated answer.
            – Giorgos Myrianthous
            Nov 8 at 10:18






            @IkeWhite My bad. See my updated answer.
            – Giorgos Myrianthous
            Nov 8 at 10:18














            up vote
            0
            down vote













            create table #temp(
            Integ Integer
            )
            insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
            (CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
            select * from #temp
            where Integ >918
            drop table #temp


            hope it helps you






            share|improve this answer

























              up vote
              0
              down vote













              create table #temp(
              Integ Integer
              )
              insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
              (CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
              select * from #temp
              where Integ >918
              drop table #temp


              hope it helps you






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                create table #temp(
                Integ Integer
                )
                insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
                (CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
                select * from #temp
                where Integ >918
                drop table #temp


                hope it helps you






                share|improve this answer












                create table #temp(
                Integ Integer
                )
                insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
                (CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
                select * from #temp
                where Integ >918
                drop table #temp


                hope it helps you







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 10:40









                Vaso Miruashvili

                33




                33






















                    Ike White is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    Ike White is a new contributor. Be nice, and check out our Code of Conduct.













                    Ike White is a new contributor. Be nice, and check out our Code of Conduct.












                    Ike White is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205251%2fmysql-select-from-text-column-with-filtering%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Schultheiß

                    Verwaltungsgliederung Dänemarks

                    Liste der Kulturdenkmale in Wilsdruff