Join with wildcard Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?What is the difference between “INNER JOIN” and “OUTER JOIN”?Difference between JOIN and INNER JOINHow can I do an UPDATE statement with JOIN in SQL?SQL JOIN using Concatenated FieldWhat's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?How to Delete using INNER JOIN with SQL Server?Efficient Four-Way Join in Oracle SQLLeft Outer join not returning expected resultSetGetting column cannot be null while trying to use 'insert into select' querySQL condition - starts with a dynamic value

What do you call a phrase that's not an idiom yet?

Gastric acid as a weapon

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

Using et al. for a last / senior author rather than for a first author

What is the musical term for a note that continously plays through a melody?

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

do i need a schengen visa for a direct flight to amsterdam?

What do you call a plan that's an alternative plan in case your initial plan fails?

Disable hyphenation for an entire paragraph

What does '1 unit of lemon juice' mean in a grandma's drink recipe?

What does the "x" in "x86" represent?

Single word antonym of "flightless"

If a contract sometimes uses the wrong name, is it still valid?

What's the purpose of writing one's academic bio in 3rd person?

3 doors, three guards, one stone

How to deal with a team lead who never gives me credit?

Does accepting a pardon have any bearing on trying that person for the same crime in a sovereign jurisdiction?

Determinant is linear as a function of each of the rows of the matrix.

Why does Python start at index -1 when indexing a list from the end?

What would be the ideal power source for a cybernetic eye?

What is the correct way to use the pinch test for dehydration?

How to motivate offshore teams and trust them to deliver?

How can I fade player when goes inside or outside of the area?

Why is "Captain Marvel" translated as male in Portugal?



Join with wildcard



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?What is the difference between “INNER JOIN” and “OUTER JOIN”?Difference between JOIN and INNER JOINHow can I do an UPDATE statement with JOIN in SQL?SQL JOIN using Concatenated FieldWhat's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?How to Delete using INNER JOIN with SQL Server?Efficient Four-Way Join in Oracle SQLLeft Outer join not returning expected resultSetGetting column cannot be null while trying to use 'insert into select' querySQL condition - starts with a dynamic value



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Table1



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C |
--------------------------------------------------------------
| 3007576 | abc | | |
| 3007879 | ab | fg | |
| 3007880 | ad | | x |
| 3007900 | | | |
|------------------------------------------------------------|


Table2



|------------------------------------------------------------|
| Para_2 | column_A | column_B | column_C |
--------------------------------------------------------------
| 100 | abcd | fgh | xyz |
| 200 | abc | fg | z |
| 300 | ab | g | xy |
|------------------------------------------------------------|


Expected Results:



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C | Para_2
--------------------------------------------------------------
| 3007576 | abc | | | 100
| 3007576 | abc | | | 200
| 3007879 | ab | fg | | 100
| 3007879 | ab | fg | | 200
| 3007880 | ad | | x | null
| 3007900 | | | | null
|------------------------------------------------------------|

select table1.*, table2.Para_2, table1.column_A
from table1
left outer join table2
on table2.column_A like ('%'||table1.column_A||'%')
and table2.column_B like ('%'||table1.column_B||'%')
and table2.column_C like ('%'||table1.column_C||'%')

where table1.column_A is not null
and table1.column_B is not null
and table1.column_C is not null


the above code seems not sufficient.. any idea?










share|improve this question
























  • The WHERE clause wont pass any table1 rows at all.

    – jarlh
    Mar 22 at 8:29

















0















Table1



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C |
--------------------------------------------------------------
| 3007576 | abc | | |
| 3007879 | ab | fg | |
| 3007880 | ad | | x |
| 3007900 | | | |
|------------------------------------------------------------|


Table2



|------------------------------------------------------------|
| Para_2 | column_A | column_B | column_C |
--------------------------------------------------------------
| 100 | abcd | fgh | xyz |
| 200 | abc | fg | z |
| 300 | ab | g | xy |
|------------------------------------------------------------|


Expected Results:



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C | Para_2
--------------------------------------------------------------
| 3007576 | abc | | | 100
| 3007576 | abc | | | 200
| 3007879 | ab | fg | | 100
| 3007879 | ab | fg | | 200
| 3007880 | ad | | x | null
| 3007900 | | | | null
|------------------------------------------------------------|

select table1.*, table2.Para_2, table1.column_A
from table1
left outer join table2
on table2.column_A like ('%'||table1.column_A||'%')
and table2.column_B like ('%'||table1.column_B||'%')
and table2.column_C like ('%'||table1.column_C||'%')

where table1.column_A is not null
and table1.column_B is not null
and table1.column_C is not null


the above code seems not sufficient.. any idea?










share|improve this question
























  • The WHERE clause wont pass any table1 rows at all.

    – jarlh
    Mar 22 at 8:29













0












0








0








Table1



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C |
--------------------------------------------------------------
| 3007576 | abc | | |
| 3007879 | ab | fg | |
| 3007880 | ad | | x |
| 3007900 | | | |
|------------------------------------------------------------|


Table2



|------------------------------------------------------------|
| Para_2 | column_A | column_B | column_C |
--------------------------------------------------------------
| 100 | abcd | fgh | xyz |
| 200 | abc | fg | z |
| 300 | ab | g | xy |
|------------------------------------------------------------|


Expected Results:



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C | Para_2
--------------------------------------------------------------
| 3007576 | abc | | | 100
| 3007576 | abc | | | 200
| 3007879 | ab | fg | | 100
| 3007879 | ab | fg | | 200
| 3007880 | ad | | x | null
| 3007900 | | | | null
|------------------------------------------------------------|

select table1.*, table2.Para_2, table1.column_A
from table1
left outer join table2
on table2.column_A like ('%'||table1.column_A||'%')
and table2.column_B like ('%'||table1.column_B||'%')
and table2.column_C like ('%'||table1.column_C||'%')

where table1.column_A is not null
and table1.column_B is not null
and table1.column_C is not null


the above code seems not sufficient.. any idea?










share|improve this question
















Table1



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C |
--------------------------------------------------------------
| 3007576 | abc | | |
| 3007879 | ab | fg | |
| 3007880 | ad | | x |
| 3007900 | | | |
|------------------------------------------------------------|


Table2



|------------------------------------------------------------|
| Para_2 | column_A | column_B | column_C |
--------------------------------------------------------------
| 100 | abcd | fgh | xyz |
| 200 | abc | fg | z |
| 300 | ab | g | xy |
|------------------------------------------------------------|


Expected Results:



|------------------------------------------------------------|
| Para_1 | column_A | column_B | column_C | Para_2
--------------------------------------------------------------
| 3007576 | abc | | | 100
| 3007576 | abc | | | 200
| 3007879 | ab | fg | | 100
| 3007879 | ab | fg | | 200
| 3007880 | ad | | x | null
| 3007900 | | | | null
|------------------------------------------------------------|

select table1.*, table2.Para_2, table1.column_A
from table1
left outer join table2
on table2.column_A like ('%'||table1.column_A||'%')
and table2.column_B like ('%'||table1.column_B||'%')
and table2.column_C like ('%'||table1.column_C||'%')

where table1.column_A is not null
and table1.column_B is not null
and table1.column_C is not null


the above code seems not sufficient.. any idea?







sql oracle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 8:30









Joakim Danielson

10.9k3725




10.9k3725










asked Mar 22 at 8:26









EricEric

1




1












  • The WHERE clause wont pass any table1 rows at all.

    – jarlh
    Mar 22 at 8:29

















  • The WHERE clause wont pass any table1 rows at all.

    – jarlh
    Mar 22 at 8:29
















The WHERE clause wont pass any table1 rows at all.

– jarlh
Mar 22 at 8:29





The WHERE clause wont pass any table1 rows at all.

– jarlh
Mar 22 at 8:29












2 Answers
2






active

oldest

votes


















0














remove where clause because in each row in your sample data there is at least one null column value with the 3 column A,B,C so it filtered all



select table1.*, table2.Para_2, table1.column_A
from table1
left outer join table2
on table2.column_A like ('%'||table1.column_A||'%')
and table2.column_B like ('%'||table1.column_B||'%')
and table2.column_C like ('%'||table1.column_C||'%')





share|improve this answer

























  • That produces 8 lines, not the wanted 6.

    – Kjetil S.
    Mar 22 at 8:56












  • @KjetilS. thanks edited

    – Zaynul Abadin Tuhin
    Mar 22 at 8:59


















0














This produces your expected result:



select table1.*, table2.Para_2
from table1 left outer join table2
on table2.column_A like '%'||table1.column_A||'%'
and table2.column_B like '%'||table1.column_B||'%'
and table2.column_C like '%'||table1.column_C||'%'
and coalesce(table1.column_a, table1.column_b, table1.column_c) is not null;


As you can see, this is almost what you had. But your where isn't needed, just an extra last line on the on condition. That extra line can also be written perhaps more clearly like this if you don't like the coalescefunction:



and not (table1.column_a is null and table1.column_b is null and table1.column_c is null);


Or:



and length(table1.column_a||table1.column_b||table1.column_c)>0;





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%2f55295573%2fjoin-with-wildcard%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














    remove where clause because in each row in your sample data there is at least one null column value with the 3 column A,B,C so it filtered all



    select table1.*, table2.Para_2, table1.column_A
    from table1
    left outer join table2
    on table2.column_A like ('%'||table1.column_A||'%')
    and table2.column_B like ('%'||table1.column_B||'%')
    and table2.column_C like ('%'||table1.column_C||'%')





    share|improve this answer

























    • That produces 8 lines, not the wanted 6.

      – Kjetil S.
      Mar 22 at 8:56












    • @KjetilS. thanks edited

      – Zaynul Abadin Tuhin
      Mar 22 at 8:59















    0














    remove where clause because in each row in your sample data there is at least one null column value with the 3 column A,B,C so it filtered all



    select table1.*, table2.Para_2, table1.column_A
    from table1
    left outer join table2
    on table2.column_A like ('%'||table1.column_A||'%')
    and table2.column_B like ('%'||table1.column_B||'%')
    and table2.column_C like ('%'||table1.column_C||'%')





    share|improve this answer

























    • That produces 8 lines, not the wanted 6.

      – Kjetil S.
      Mar 22 at 8:56












    • @KjetilS. thanks edited

      – Zaynul Abadin Tuhin
      Mar 22 at 8:59













    0












    0








    0







    remove where clause because in each row in your sample data there is at least one null column value with the 3 column A,B,C so it filtered all



    select table1.*, table2.Para_2, table1.column_A
    from table1
    left outer join table2
    on table2.column_A like ('%'||table1.column_A||'%')
    and table2.column_B like ('%'||table1.column_B||'%')
    and table2.column_C like ('%'||table1.column_C||'%')





    share|improve this answer















    remove where clause because in each row in your sample data there is at least one null column value with the 3 column A,B,C so it filtered all



    select table1.*, table2.Para_2, table1.column_A
    from table1
    left outer join table2
    on table2.column_A like ('%'||table1.column_A||'%')
    and table2.column_B like ('%'||table1.column_B||'%')
    and table2.column_C like ('%'||table1.column_C||'%')






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 22 at 8:58

























    answered Mar 22 at 8:31









    Zaynul Abadin TuhinZaynul Abadin Tuhin

    19.3k31135




    19.3k31135












    • That produces 8 lines, not the wanted 6.

      – Kjetil S.
      Mar 22 at 8:56












    • @KjetilS. thanks edited

      – Zaynul Abadin Tuhin
      Mar 22 at 8:59

















    • That produces 8 lines, not the wanted 6.

      – Kjetil S.
      Mar 22 at 8:56












    • @KjetilS. thanks edited

      – Zaynul Abadin Tuhin
      Mar 22 at 8:59
















    That produces 8 lines, not the wanted 6.

    – Kjetil S.
    Mar 22 at 8:56






    That produces 8 lines, not the wanted 6.

    – Kjetil S.
    Mar 22 at 8:56














    @KjetilS. thanks edited

    – Zaynul Abadin Tuhin
    Mar 22 at 8:59





    @KjetilS. thanks edited

    – Zaynul Abadin Tuhin
    Mar 22 at 8:59













    0














    This produces your expected result:



    select table1.*, table2.Para_2
    from table1 left outer join table2
    on table2.column_A like '%'||table1.column_A||'%'
    and table2.column_B like '%'||table1.column_B||'%'
    and table2.column_C like '%'||table1.column_C||'%'
    and coalesce(table1.column_a, table1.column_b, table1.column_c) is not null;


    As you can see, this is almost what you had. But your where isn't needed, just an extra last line on the on condition. That extra line can also be written perhaps more clearly like this if you don't like the coalescefunction:



    and not (table1.column_a is null and table1.column_b is null and table1.column_c is null);


    Or:



    and length(table1.column_a||table1.column_b||table1.column_c)>0;





    share|improve this answer





























      0














      This produces your expected result:



      select table1.*, table2.Para_2
      from table1 left outer join table2
      on table2.column_A like '%'||table1.column_A||'%'
      and table2.column_B like '%'||table1.column_B||'%'
      and table2.column_C like '%'||table1.column_C||'%'
      and coalesce(table1.column_a, table1.column_b, table1.column_c) is not null;


      As you can see, this is almost what you had. But your where isn't needed, just an extra last line on the on condition. That extra line can also be written perhaps more clearly like this if you don't like the coalescefunction:



      and not (table1.column_a is null and table1.column_b is null and table1.column_c is null);


      Or:



      and length(table1.column_a||table1.column_b||table1.column_c)>0;





      share|improve this answer



























        0












        0








        0







        This produces your expected result:



        select table1.*, table2.Para_2
        from table1 left outer join table2
        on table2.column_A like '%'||table1.column_A||'%'
        and table2.column_B like '%'||table1.column_B||'%'
        and table2.column_C like '%'||table1.column_C||'%'
        and coalesce(table1.column_a, table1.column_b, table1.column_c) is not null;


        As you can see, this is almost what you had. But your where isn't needed, just an extra last line on the on condition. That extra line can also be written perhaps more clearly like this if you don't like the coalescefunction:



        and not (table1.column_a is null and table1.column_b is null and table1.column_c is null);


        Or:



        and length(table1.column_a||table1.column_b||table1.column_c)>0;





        share|improve this answer















        This produces your expected result:



        select table1.*, table2.Para_2
        from table1 left outer join table2
        on table2.column_A like '%'||table1.column_A||'%'
        and table2.column_B like '%'||table1.column_B||'%'
        and table2.column_C like '%'||table1.column_C||'%'
        and coalesce(table1.column_a, table1.column_b, table1.column_c) is not null;


        As you can see, this is almost what you had. But your where isn't needed, just an extra last line on the on condition. That extra line can also be written perhaps more clearly like this if you don't like the coalescefunction:



        and not (table1.column_a is null and table1.column_b is null and table1.column_c is null);


        Or:



        and length(table1.column_a||table1.column_b||table1.column_c)>0;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 22 at 9:03

























        answered Mar 22 at 8:54









        Kjetil S.Kjetil S.

        1,411812




        1,411812



























            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%2f55295573%2fjoin-with-wildcard%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현