MySQL Like search for any Japanese character in a string












0















I'm working on a Japanese website development. I have something like the following database in MySQL:



+--------+-------+
| id | kanji |
+--------+-------+
| 1 | 明 |
| 2 | 令 |
| 3 | 暗 |
| 4 | 週 |
+--------+-------+


I need to do a SELECT so when the value "明暗" is searched, rows 1 and 3 are selected. I know REGEXP could do something like that with the pattern [...], but it does not seem to work good with Chinese (or in this case, Japanese) characters. It shows a wider range of results. It seems like LIKE work better with these charset, but I don't know how to do so. Does anyone know how to do this query?



Thanks!



----- EDIT -----



For REGEXP I'm trying the following query:



SELECT id, kanji
FROM kanjidic2
WHERE kanji REGEXP '[明暗]';


However, these are some of the results (the query found 3842 matches, where there whould be only 2).



results for query










share|improve this question

























  • Do you mean this? SELECT * FROM TABLE WHERE KANJI IN (N'明','暗');

    – dwir182
    Nov 14 '18 at 2:09











  • I know spliting search would work (even an OR would do the job), but I can't slipt the string, as it is given from a variable in php from a searching bar.

    – Juan Camilo Orjuela
    Nov 14 '18 at 2:23











  • Which MySQL version are you using? Multibytes characters on REGEXP was introduced at version 8.0 so it won't work properly with the older versions. dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html ( Regular expression support )

    – akky
    Nov 14 '18 at 3:25











  • @akky I'll transcript the information as I am wuite new into mySQL: innodb_version: 5.6.39 protocol_version: 10 I guess it is version 10, but when I run REGEXP, the result of the query is way more rows than the two with the two characters in the query :/

    – Juan Camilo Orjuela
    Nov 14 '18 at 13:33











  • You said in a previous comment that you are unable to split the search string. Why is that? It shouldn't matter whether it's parsed as a PHP variable.

    – Martin
    Nov 14 '18 at 13:58


















0















I'm working on a Japanese website development. I have something like the following database in MySQL:



+--------+-------+
| id | kanji |
+--------+-------+
| 1 | 明 |
| 2 | 令 |
| 3 | 暗 |
| 4 | 週 |
+--------+-------+


I need to do a SELECT so when the value "明暗" is searched, rows 1 and 3 are selected. I know REGEXP could do something like that with the pattern [...], but it does not seem to work good with Chinese (or in this case, Japanese) characters. It shows a wider range of results. It seems like LIKE work better with these charset, but I don't know how to do so. Does anyone know how to do this query?



Thanks!



----- EDIT -----



For REGEXP I'm trying the following query:



SELECT id, kanji
FROM kanjidic2
WHERE kanji REGEXP '[明暗]';


However, these are some of the results (the query found 3842 matches, where there whould be only 2).



results for query










share|improve this question

























  • Do you mean this? SELECT * FROM TABLE WHERE KANJI IN (N'明','暗');

    – dwir182
    Nov 14 '18 at 2:09











  • I know spliting search would work (even an OR would do the job), but I can't slipt the string, as it is given from a variable in php from a searching bar.

    – Juan Camilo Orjuela
    Nov 14 '18 at 2:23











  • Which MySQL version are you using? Multibytes characters on REGEXP was introduced at version 8.0 so it won't work properly with the older versions. dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html ( Regular expression support )

    – akky
    Nov 14 '18 at 3:25











  • @akky I'll transcript the information as I am wuite new into mySQL: innodb_version: 5.6.39 protocol_version: 10 I guess it is version 10, but when I run REGEXP, the result of the query is way more rows than the two with the two characters in the query :/

    – Juan Camilo Orjuela
    Nov 14 '18 at 13:33











  • You said in a previous comment that you are unable to split the search string. Why is that? It shouldn't matter whether it's parsed as a PHP variable.

    – Martin
    Nov 14 '18 at 13:58
















0












0








0








I'm working on a Japanese website development. I have something like the following database in MySQL:



+--------+-------+
| id | kanji |
+--------+-------+
| 1 | 明 |
| 2 | 令 |
| 3 | 暗 |
| 4 | 週 |
+--------+-------+


I need to do a SELECT so when the value "明暗" is searched, rows 1 and 3 are selected. I know REGEXP could do something like that with the pattern [...], but it does not seem to work good with Chinese (or in this case, Japanese) characters. It shows a wider range of results. It seems like LIKE work better with these charset, but I don't know how to do so. Does anyone know how to do this query?



Thanks!



----- EDIT -----



For REGEXP I'm trying the following query:



SELECT id, kanji
FROM kanjidic2
WHERE kanji REGEXP '[明暗]';


However, these are some of the results (the query found 3842 matches, where there whould be only 2).



results for query










share|improve this question
















I'm working on a Japanese website development. I have something like the following database in MySQL:



+--------+-------+
| id | kanji |
+--------+-------+
| 1 | 明 |
| 2 | 令 |
| 3 | 暗 |
| 4 | 週 |
+--------+-------+


I need to do a SELECT so when the value "明暗" is searched, rows 1 and 3 are selected. I know REGEXP could do something like that with the pattern [...], but it does not seem to work good with Chinese (or in this case, Japanese) characters. It shows a wider range of results. It seems like LIKE work better with these charset, but I don't know how to do so. Does anyone know how to do this query?



Thanks!



----- EDIT -----



For REGEXP I'm trying the following query:



SELECT id, kanji
FROM kanjidic2
WHERE kanji REGEXP '[明暗]';


However, these are some of the results (the query found 3842 matches, where there whould be only 2).



results for query







mysql sql sql-like japanese






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 13:37







Juan Camilo Orjuela

















asked Nov 14 '18 at 1:46









Juan Camilo OrjuelaJuan Camilo Orjuela

33




33













  • Do you mean this? SELECT * FROM TABLE WHERE KANJI IN (N'明','暗');

    – dwir182
    Nov 14 '18 at 2:09











  • I know spliting search would work (even an OR would do the job), but I can't slipt the string, as it is given from a variable in php from a searching bar.

    – Juan Camilo Orjuela
    Nov 14 '18 at 2:23











  • Which MySQL version are you using? Multibytes characters on REGEXP was introduced at version 8.0 so it won't work properly with the older versions. dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html ( Regular expression support )

    – akky
    Nov 14 '18 at 3:25











  • @akky I'll transcript the information as I am wuite new into mySQL: innodb_version: 5.6.39 protocol_version: 10 I guess it is version 10, but when I run REGEXP, the result of the query is way more rows than the two with the two characters in the query :/

    – Juan Camilo Orjuela
    Nov 14 '18 at 13:33











  • You said in a previous comment that you are unable to split the search string. Why is that? It shouldn't matter whether it's parsed as a PHP variable.

    – Martin
    Nov 14 '18 at 13:58





















  • Do you mean this? SELECT * FROM TABLE WHERE KANJI IN (N'明','暗');

    – dwir182
    Nov 14 '18 at 2:09











  • I know spliting search would work (even an OR would do the job), but I can't slipt the string, as it is given from a variable in php from a searching bar.

    – Juan Camilo Orjuela
    Nov 14 '18 at 2:23











  • Which MySQL version are you using? Multibytes characters on REGEXP was introduced at version 8.0 so it won't work properly with the older versions. dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html ( Regular expression support )

    – akky
    Nov 14 '18 at 3:25











  • @akky I'll transcript the information as I am wuite new into mySQL: innodb_version: 5.6.39 protocol_version: 10 I guess it is version 10, but when I run REGEXP, the result of the query is way more rows than the two with the two characters in the query :/

    – Juan Camilo Orjuela
    Nov 14 '18 at 13:33











  • You said in a previous comment that you are unable to split the search string. Why is that? It shouldn't matter whether it's parsed as a PHP variable.

    – Martin
    Nov 14 '18 at 13:58



















Do you mean this? SELECT * FROM TABLE WHERE KANJI IN (N'明','暗');

– dwir182
Nov 14 '18 at 2:09





Do you mean this? SELECT * FROM TABLE WHERE KANJI IN (N'明','暗');

– dwir182
Nov 14 '18 at 2:09













I know spliting search would work (even an OR would do the job), but I can't slipt the string, as it is given from a variable in php from a searching bar.

– Juan Camilo Orjuela
Nov 14 '18 at 2:23





I know spliting search would work (even an OR would do the job), but I can't slipt the string, as it is given from a variable in php from a searching bar.

– Juan Camilo Orjuela
Nov 14 '18 at 2:23













Which MySQL version are you using? Multibytes characters on REGEXP was introduced at version 8.0 so it won't work properly with the older versions. dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html ( Regular expression support )

– akky
Nov 14 '18 at 3:25





Which MySQL version are you using? Multibytes characters on REGEXP was introduced at version 8.0 so it won't work properly with the older versions. dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html ( Regular expression support )

– akky
Nov 14 '18 at 3:25













@akky I'll transcript the information as I am wuite new into mySQL: innodb_version: 5.6.39 protocol_version: 10 I guess it is version 10, but when I run REGEXP, the result of the query is way more rows than the two with the two characters in the query :/

– Juan Camilo Orjuela
Nov 14 '18 at 13:33





@akky I'll transcript the information as I am wuite new into mySQL: innodb_version: 5.6.39 protocol_version: 10 I guess it is version 10, but when I run REGEXP, the result of the query is way more rows than the two with the two characters in the query :/

– Juan Camilo Orjuela
Nov 14 '18 at 13:33













You said in a previous comment that you are unable to split the search string. Why is that? It shouldn't matter whether it's parsed as a PHP variable.

– Martin
Nov 14 '18 at 13:58







You said in a previous comment that you are unable to split the search string. Why is that? It shouldn't matter whether it's parsed as a PHP variable.

– Martin
Nov 14 '18 at 13:58














2 Answers
2






active

oldest

votes


















0














SELECT *



FROM Table



WHERE REGEXP_LIKE(column, '%your character%')



you can use below if do you need



REGEXP_LIKE,



REGEXP_REPLACE,



REGEXP_INSTR,



REGEXP_SUBSTR






share|improve this answer


























  • Thanks!, but that query would look for a range. Actually, I don't have problems with regular LIKE queries with unicode characters without 'N', but the query I'm currently looking for is for it to look for any of the characters in the string. The problem with unicode caracters is with REGEXP, not with LIKE.

    – Juan Camilo Orjuela
    Nov 14 '18 at 13:21



















0














Solved with php. Thank you all!






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',
    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%2f53292020%2fmysql-like-search-for-any-japanese-character-in-a-string%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    SELECT *



    FROM Table



    WHERE REGEXP_LIKE(column, '%your character%')



    you can use below if do you need



    REGEXP_LIKE,



    REGEXP_REPLACE,



    REGEXP_INSTR,



    REGEXP_SUBSTR






    share|improve this answer


























    • Thanks!, but that query would look for a range. Actually, I don't have problems with regular LIKE queries with unicode characters without 'N', but the query I'm currently looking for is for it to look for any of the characters in the string. The problem with unicode caracters is with REGEXP, not with LIKE.

      – Juan Camilo Orjuela
      Nov 14 '18 at 13:21
















    0














    SELECT *



    FROM Table



    WHERE REGEXP_LIKE(column, '%your character%')



    you can use below if do you need



    REGEXP_LIKE,



    REGEXP_REPLACE,



    REGEXP_INSTR,



    REGEXP_SUBSTR






    share|improve this answer


























    • Thanks!, but that query would look for a range. Actually, I don't have problems with regular LIKE queries with unicode characters without 'N', but the query I'm currently looking for is for it to look for any of the characters in the string. The problem with unicode caracters is with REGEXP, not with LIKE.

      – Juan Camilo Orjuela
      Nov 14 '18 at 13:21














    0












    0








    0







    SELECT *



    FROM Table



    WHERE REGEXP_LIKE(column, '%your character%')



    you can use below if do you need



    REGEXP_LIKE,



    REGEXP_REPLACE,



    REGEXP_INSTR,



    REGEXP_SUBSTR






    share|improve this answer















    SELECT *



    FROM Table



    WHERE REGEXP_LIKE(column, '%your character%')



    you can use below if do you need



    REGEXP_LIKE,



    REGEXP_REPLACE,



    REGEXP_INSTR,



    REGEXP_SUBSTR







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 14 '18 at 13:33

























    answered Nov 14 '18 at 7:09









    yusuf hayırseveryusuf hayırsever

    1877




    1877













    • Thanks!, but that query would look for a range. Actually, I don't have problems with regular LIKE queries with unicode characters without 'N', but the query I'm currently looking for is for it to look for any of the characters in the string. The problem with unicode caracters is with REGEXP, not with LIKE.

      – Juan Camilo Orjuela
      Nov 14 '18 at 13:21



















    • Thanks!, but that query would look for a range. Actually, I don't have problems with regular LIKE queries with unicode characters without 'N', but the query I'm currently looking for is for it to look for any of the characters in the string. The problem with unicode caracters is with REGEXP, not with LIKE.

      – Juan Camilo Orjuela
      Nov 14 '18 at 13:21

















    Thanks!, but that query would look for a range. Actually, I don't have problems with regular LIKE queries with unicode characters without 'N', but the query I'm currently looking for is for it to look for any of the characters in the string. The problem with unicode caracters is with REGEXP, not with LIKE.

    – Juan Camilo Orjuela
    Nov 14 '18 at 13:21





    Thanks!, but that query would look for a range. Actually, I don't have problems with regular LIKE queries with unicode characters without 'N', but the query I'm currently looking for is for it to look for any of the characters in the string. The problem with unicode caracters is with REGEXP, not with LIKE.

    – Juan Camilo Orjuela
    Nov 14 '18 at 13:21













    0














    Solved with php. Thank you all!






    share|improve this answer




























      0














      Solved with php. Thank you all!






      share|improve this answer


























        0












        0








        0







        Solved with php. Thank you all!






        share|improve this answer













        Solved with php. Thank you all!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 16:35









        Juan Camilo OrjuelaJuan Camilo Orjuela

        33




        33






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292020%2fmysql-like-search-for-any-japanese-character-in-a-string%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

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python