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;
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
add a comment |
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
The WHERE clause wont pass any table1 rows at all.
– jarlh
Mar 22 at 8:29
add a comment |
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
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
sql oracle
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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||'%')
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
add a comment |
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 coalesce
function:
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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||'%')
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
add a comment |
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||'%')
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
add a comment |
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||'%')
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||'%')
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
add a comment |
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
add a comment |
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 coalesce
function:
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;
add a comment |
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 coalesce
function:
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;
add a comment |
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 coalesce
function:
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;
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 coalesce
function:
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;
edited Mar 22 at 9:03
answered Mar 22 at 8:54
Kjetil S.Kjetil S.
1,411812
1,411812
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
The WHERE clause wont pass any table1 rows at all.
– jarlh
Mar 22 at 8:29