Search similar value in another table using IN (SQLite)












0















I'm using SQLite to deal with tons of data (like 100gb of data).



I need to seach the value of one column in other table in the fastest way possible.
For example, I need to find the following values of Table 1



[COD]
C62
K801


And then find them in Table 2:



[COD_2]
C60-C63
K80-K81


My desired result is something like:



[COD_1]  [COD_2]
C62 C60-C63
K801 K80-K81


Since I have a lot of data, it is inefficient to do something like:



SELECT * 
FROM TABLE_1, TABLE_2
WHERE COD_1 LIKE '%' || COD_2 || '%';


Instead, I was trying to do this:



SELECT *
FROM TABLE_1
WHERE COD_1 IN (SELECT COD_2 FROM TABLE_2);


Of course that this doesn't result because the codes are not exactly the sames. Is there a way to search for similar values of one column (something like the LIKE operator) in other table by using IN? Or other way that doesn't cross TABLE_1 and TABLE_2?



Thank you!!!
useful to me.










share|improve this question























  • Are you trying to store a range in a single value (Bad idea, btw)? If so, how is K801 in K80-K81?

    – Shawn
    Nov 22 '18 at 21:32
















0















I'm using SQLite to deal with tons of data (like 100gb of data).



I need to seach the value of one column in other table in the fastest way possible.
For example, I need to find the following values of Table 1



[COD]
C62
K801


And then find them in Table 2:



[COD_2]
C60-C63
K80-K81


My desired result is something like:



[COD_1]  [COD_2]
C62 C60-C63
K801 K80-K81


Since I have a lot of data, it is inefficient to do something like:



SELECT * 
FROM TABLE_1, TABLE_2
WHERE COD_1 LIKE '%' || COD_2 || '%';


Instead, I was trying to do this:



SELECT *
FROM TABLE_1
WHERE COD_1 IN (SELECT COD_2 FROM TABLE_2);


Of course that this doesn't result because the codes are not exactly the sames. Is there a way to search for similar values of one column (something like the LIKE operator) in other table by using IN? Or other way that doesn't cross TABLE_1 and TABLE_2?



Thank you!!!
useful to me.










share|improve this question























  • Are you trying to store a range in a single value (Bad idea, btw)? If so, how is K801 in K80-K81?

    – Shawn
    Nov 22 '18 at 21:32














0












0








0








I'm using SQLite to deal with tons of data (like 100gb of data).



I need to seach the value of one column in other table in the fastest way possible.
For example, I need to find the following values of Table 1



[COD]
C62
K801


And then find them in Table 2:



[COD_2]
C60-C63
K80-K81


My desired result is something like:



[COD_1]  [COD_2]
C62 C60-C63
K801 K80-K81


Since I have a lot of data, it is inefficient to do something like:



SELECT * 
FROM TABLE_1, TABLE_2
WHERE COD_1 LIKE '%' || COD_2 || '%';


Instead, I was trying to do this:



SELECT *
FROM TABLE_1
WHERE COD_1 IN (SELECT COD_2 FROM TABLE_2);


Of course that this doesn't result because the codes are not exactly the sames. Is there a way to search for similar values of one column (something like the LIKE operator) in other table by using IN? Or other way that doesn't cross TABLE_1 and TABLE_2?



Thank you!!!
useful to me.










share|improve this question














I'm using SQLite to deal with tons of data (like 100gb of data).



I need to seach the value of one column in other table in the fastest way possible.
For example, I need to find the following values of Table 1



[COD]
C62
K801


And then find them in Table 2:



[COD_2]
C60-C63
K80-K81


My desired result is something like:



[COD_1]  [COD_2]
C62 C60-C63
K801 K80-K81


Since I have a lot of data, it is inefficient to do something like:



SELECT * 
FROM TABLE_1, TABLE_2
WHERE COD_1 LIKE '%' || COD_2 || '%';


Instead, I was trying to do this:



SELECT *
FROM TABLE_1
WHERE COD_1 IN (SELECT COD_2 FROM TABLE_2);


Of course that this doesn't result because the codes are not exactly the sames. Is there a way to search for similar values of one column (something like the LIKE operator) in other table by using IN? Or other way that doesn't cross TABLE_1 and TABLE_2?



Thank you!!!
useful to me.







sqlite






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 20:19









Valeria Lobos OssandónValeria Lobos Ossandón

7629




7629













  • Are you trying to store a range in a single value (Bad idea, btw)? If so, how is K801 in K80-K81?

    – Shawn
    Nov 22 '18 at 21:32



















  • Are you trying to store a range in a single value (Bad idea, btw)? If so, how is K801 in K80-K81?

    – Shawn
    Nov 22 '18 at 21:32

















Are you trying to store a range in a single value (Bad idea, btw)? If so, how is K801 in K80-K81?

– Shawn
Nov 22 '18 at 21:32





Are you trying to store a range in a single value (Bad idea, btw)? If so, how is K801 in K80-K81?

– Shawn
Nov 22 '18 at 21:32












1 Answer
1






active

oldest

votes


















0














Based on the small data set shown, and my presumed answer to @Shawn's question (K801 is a typo and is meant to be K80 or K81) I assume the following problem description:



Find a row in COD_2 such that the value in COD_1 is between {value1}-{value2} in COD_2; the - being significant and dependable.



I cannot speak to speed, but I would approach it this way:



SELECT value1, value2
from COD_1,COD_2
where value1 between substr(value2,1,instr(value2,'-')-1) and substr(value2,instr(value2,'-')+1)


The thought being: split the value from COD-2 into a "start" and an "end" value.






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%2f53437582%2fsearch-similar-value-in-another-table-using-in-sqlite%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Based on the small data set shown, and my presumed answer to @Shawn's question (K801 is a typo and is meant to be K80 or K81) I assume the following problem description:



    Find a row in COD_2 such that the value in COD_1 is between {value1}-{value2} in COD_2; the - being significant and dependable.



    I cannot speak to speed, but I would approach it this way:



    SELECT value1, value2
    from COD_1,COD_2
    where value1 between substr(value2,1,instr(value2,'-')-1) and substr(value2,instr(value2,'-')+1)


    The thought being: split the value from COD-2 into a "start" and an "end" value.






    share|improve this answer




























      0














      Based on the small data set shown, and my presumed answer to @Shawn's question (K801 is a typo and is meant to be K80 or K81) I assume the following problem description:



      Find a row in COD_2 such that the value in COD_1 is between {value1}-{value2} in COD_2; the - being significant and dependable.



      I cannot speak to speed, but I would approach it this way:



      SELECT value1, value2
      from COD_1,COD_2
      where value1 between substr(value2,1,instr(value2,'-')-1) and substr(value2,instr(value2,'-')+1)


      The thought being: split the value from COD-2 into a "start" and an "end" value.






      share|improve this answer


























        0












        0








        0







        Based on the small data set shown, and my presumed answer to @Shawn's question (K801 is a typo and is meant to be K80 or K81) I assume the following problem description:



        Find a row in COD_2 such that the value in COD_1 is between {value1}-{value2} in COD_2; the - being significant and dependable.



        I cannot speak to speed, but I would approach it this way:



        SELECT value1, value2
        from COD_1,COD_2
        where value1 between substr(value2,1,instr(value2,'-')-1) and substr(value2,instr(value2,'-')+1)


        The thought being: split the value from COD-2 into a "start" and an "end" value.






        share|improve this answer













        Based on the small data set shown, and my presumed answer to @Shawn's question (K801 is a typo and is meant to be K80 or K81) I assume the following problem description:



        Find a row in COD_2 such that the value in COD_1 is between {value1}-{value2} in COD_2; the - being significant and dependable.



        I cannot speak to speed, but I would approach it this way:



        SELECT value1, value2
        from COD_1,COD_2
        where value1 between substr(value2,1,instr(value2,'-')-1) and substr(value2,instr(value2,'-')+1)


        The thought being: split the value from COD-2 into a "start" and an "end" value.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 22:25









        DinoCoderSaurusDinoCoderSaurus

        1,014158




        1,014158
































            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%2f53437582%2fsearch-similar-value-in-another-table-using-in-sqlite%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy