select matching string from another table oracle











up vote
0
down vote

favorite












I have a database (Oracle) Table A with some strings in one of columns, Now I want to get matching records from Table B against each column value of Table A for example,



Table A



Name
-----------
ABC
DEE
GHI
JKL


Table B



Name
-----------
ABC
DEF
GHI
JKL
MNO
PQR


Now i want that each string in Table A must be checked against Table B's column and if some string is found almost identical then it should appear against original Value as per below



Table OutPut



Name      Matched
--------|----------
ABC | ABC
DEE | DEF
GHI | GHI
JKL | JKL


I have tried following query



with data as(
SELECT Name FROM TABLE_A UNION ALL
SELECT Name FROM TABLE_B
)
SELECT Name
FROM
(
SELECT t.*,utl_match.edit_distance_similarity(upper(Name),upper('DEE')) eds
FROM data t
ORDER BY eds DESC
)
WHERE rownum = 1


but problem is that using this query i can check only one record at a time and that too against a hard coded string. Is there any way to check whole column from Table A one by one against Table B and produce result in output against each string.










share|improve this question






















  • By almost identical, you mean 1 or more characters matching or 2 or more characters matching?
    – Gauravsa
    Nov 7 at 11:57










  • I have names like unilever Limited in Table A that might be unilever Ltd in Table B, also like it may be "Gauravsa & Company" in Table A and "Gauravsa and Company" in Table B.
    – Baba Fooka
    Nov 7 at 12:07










  • Which version of Oracle are you using?
    – APC
    Nov 7 at 16:30















up vote
0
down vote

favorite












I have a database (Oracle) Table A with some strings in one of columns, Now I want to get matching records from Table B against each column value of Table A for example,



Table A



Name
-----------
ABC
DEE
GHI
JKL


Table B



Name
-----------
ABC
DEF
GHI
JKL
MNO
PQR


Now i want that each string in Table A must be checked against Table B's column and if some string is found almost identical then it should appear against original Value as per below



Table OutPut



Name      Matched
--------|----------
ABC | ABC
DEE | DEF
GHI | GHI
JKL | JKL


I have tried following query



with data as(
SELECT Name FROM TABLE_A UNION ALL
SELECT Name FROM TABLE_B
)
SELECT Name
FROM
(
SELECT t.*,utl_match.edit_distance_similarity(upper(Name),upper('DEE')) eds
FROM data t
ORDER BY eds DESC
)
WHERE rownum = 1


but problem is that using this query i can check only one record at a time and that too against a hard coded string. Is there any way to check whole column from Table A one by one against Table B and produce result in output against each string.










share|improve this question






















  • By almost identical, you mean 1 or more characters matching or 2 or more characters matching?
    – Gauravsa
    Nov 7 at 11:57










  • I have names like unilever Limited in Table A that might be unilever Ltd in Table B, also like it may be "Gauravsa & Company" in Table A and "Gauravsa and Company" in Table B.
    – Baba Fooka
    Nov 7 at 12:07










  • Which version of Oracle are you using?
    – APC
    Nov 7 at 16:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a database (Oracle) Table A with some strings in one of columns, Now I want to get matching records from Table B against each column value of Table A for example,



Table A



Name
-----------
ABC
DEE
GHI
JKL


Table B



Name
-----------
ABC
DEF
GHI
JKL
MNO
PQR


Now i want that each string in Table A must be checked against Table B's column and if some string is found almost identical then it should appear against original Value as per below



Table OutPut



Name      Matched
--------|----------
ABC | ABC
DEE | DEF
GHI | GHI
JKL | JKL


I have tried following query



with data as(
SELECT Name FROM TABLE_A UNION ALL
SELECT Name FROM TABLE_B
)
SELECT Name
FROM
(
SELECT t.*,utl_match.edit_distance_similarity(upper(Name),upper('DEE')) eds
FROM data t
ORDER BY eds DESC
)
WHERE rownum = 1


but problem is that using this query i can check only one record at a time and that too against a hard coded string. Is there any way to check whole column from Table A one by one against Table B and produce result in output against each string.










share|improve this question













I have a database (Oracle) Table A with some strings in one of columns, Now I want to get matching records from Table B against each column value of Table A for example,



Table A



Name
-----------
ABC
DEE
GHI
JKL


Table B



Name
-----------
ABC
DEF
GHI
JKL
MNO
PQR


Now i want that each string in Table A must be checked against Table B's column and if some string is found almost identical then it should appear against original Value as per below



Table OutPut



Name      Matched
--------|----------
ABC | ABC
DEE | DEF
GHI | GHI
JKL | JKL


I have tried following query



with data as(
SELECT Name FROM TABLE_A UNION ALL
SELECT Name FROM TABLE_B
)
SELECT Name
FROM
(
SELECT t.*,utl_match.edit_distance_similarity(upper(Name),upper('DEE')) eds
FROM data t
ORDER BY eds DESC
)
WHERE rownum = 1


but problem is that using this query i can check only one record at a time and that too against a hard coded string. Is there any way to check whole column from Table A one by one against Table B and produce result in output against each string.







oracle






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 11:07









Baba Fooka

1




1












  • By almost identical, you mean 1 or more characters matching or 2 or more characters matching?
    – Gauravsa
    Nov 7 at 11:57










  • I have names like unilever Limited in Table A that might be unilever Ltd in Table B, also like it may be "Gauravsa & Company" in Table A and "Gauravsa and Company" in Table B.
    – Baba Fooka
    Nov 7 at 12:07










  • Which version of Oracle are you using?
    – APC
    Nov 7 at 16:30


















  • By almost identical, you mean 1 or more characters matching or 2 or more characters matching?
    – Gauravsa
    Nov 7 at 11:57










  • I have names like unilever Limited in Table A that might be unilever Ltd in Table B, also like it may be "Gauravsa & Company" in Table A and "Gauravsa and Company" in Table B.
    – Baba Fooka
    Nov 7 at 12:07










  • Which version of Oracle are you using?
    – APC
    Nov 7 at 16:30
















By almost identical, you mean 1 or more characters matching or 2 or more characters matching?
– Gauravsa
Nov 7 at 11:57




By almost identical, you mean 1 or more characters matching or 2 or more characters matching?
– Gauravsa
Nov 7 at 11:57












I have names like unilever Limited in Table A that might be unilever Ltd in Table B, also like it may be "Gauravsa & Company" in Table A and "Gauravsa and Company" in Table B.
– Baba Fooka
Nov 7 at 12:07




I have names like unilever Limited in Table A that might be unilever Ltd in Table B, also like it may be "Gauravsa & Company" in Table A and "Gauravsa and Company" in Table B.
– Baba Fooka
Nov 7 at 12:07












Which version of Oracle are you using?
– APC
Nov 7 at 16:30




Which version of Oracle are you using?
– APC
Nov 7 at 16:30












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Not too clever (hint: performance issue, but - see if it helps. Might be OK if there aren't too many rows involved.



You need lines 21 onwards.



I set similarity to be greater than 80 - adjust it, if needed (which is very probable, as data you posted is really sample data).



SQL> WITH ta (name)
2 AS (SELECT 'ABC' FROM DUAL
3 UNION ALL
4 SELECT 'DEE' FROM DUAL
5 UNION ALL
6 SELECT 'GHI' FROM DUAL
7 UNION ALL
8 SELECT 'JKL' FROM DUAL),
9 tb (name)
10 AS (SELECT 'ABC' FROM DUAL
11 UNION ALL
12 SELECT 'DEF' FROM DUAL
13 UNION ALL
14 SELECT 'GHI' FROM DUAL
15 UNION ALL
16 SELECT 'JKL' FROM DUAL
17 UNION ALL
18 SELECT 'MNO' FROM DUAL
19 UNION ALL
20 SELECT 'PQR' FROM DUAL)
21 SELECT ta.name,
22 tb.name,
23 UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) sim
24 FROM ta, tb
25 WHERE UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) > 80
26 ;

NAM NAM SIM
--- --- ----------
ABC ABC 100
DEE DEF 82
GHI GHI 100
JKL JKL 100

SQL>





share|improve this answer





















  • With a little change its what i want but you are right performance is a concern using this.
    – Baba Fooka
    Nov 7 at 12:15











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


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188266%2fselect-matching-string-from-another-table-oracle%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








up vote
0
down vote













Not too clever (hint: performance issue, but - see if it helps. Might be OK if there aren't too many rows involved.



You need lines 21 onwards.



I set similarity to be greater than 80 - adjust it, if needed (which is very probable, as data you posted is really sample data).



SQL> WITH ta (name)
2 AS (SELECT 'ABC' FROM DUAL
3 UNION ALL
4 SELECT 'DEE' FROM DUAL
5 UNION ALL
6 SELECT 'GHI' FROM DUAL
7 UNION ALL
8 SELECT 'JKL' FROM DUAL),
9 tb (name)
10 AS (SELECT 'ABC' FROM DUAL
11 UNION ALL
12 SELECT 'DEF' FROM DUAL
13 UNION ALL
14 SELECT 'GHI' FROM DUAL
15 UNION ALL
16 SELECT 'JKL' FROM DUAL
17 UNION ALL
18 SELECT 'MNO' FROM DUAL
19 UNION ALL
20 SELECT 'PQR' FROM DUAL)
21 SELECT ta.name,
22 tb.name,
23 UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) sim
24 FROM ta, tb
25 WHERE UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) > 80
26 ;

NAM NAM SIM
--- --- ----------
ABC ABC 100
DEE DEF 82
GHI GHI 100
JKL JKL 100

SQL>





share|improve this answer





















  • With a little change its what i want but you are right performance is a concern using this.
    – Baba Fooka
    Nov 7 at 12:15















up vote
0
down vote













Not too clever (hint: performance issue, but - see if it helps. Might be OK if there aren't too many rows involved.



You need lines 21 onwards.



I set similarity to be greater than 80 - adjust it, if needed (which is very probable, as data you posted is really sample data).



SQL> WITH ta (name)
2 AS (SELECT 'ABC' FROM DUAL
3 UNION ALL
4 SELECT 'DEE' FROM DUAL
5 UNION ALL
6 SELECT 'GHI' FROM DUAL
7 UNION ALL
8 SELECT 'JKL' FROM DUAL),
9 tb (name)
10 AS (SELECT 'ABC' FROM DUAL
11 UNION ALL
12 SELECT 'DEF' FROM DUAL
13 UNION ALL
14 SELECT 'GHI' FROM DUAL
15 UNION ALL
16 SELECT 'JKL' FROM DUAL
17 UNION ALL
18 SELECT 'MNO' FROM DUAL
19 UNION ALL
20 SELECT 'PQR' FROM DUAL)
21 SELECT ta.name,
22 tb.name,
23 UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) sim
24 FROM ta, tb
25 WHERE UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) > 80
26 ;

NAM NAM SIM
--- --- ----------
ABC ABC 100
DEE DEF 82
GHI GHI 100
JKL JKL 100

SQL>





share|improve this answer





















  • With a little change its what i want but you are right performance is a concern using this.
    – Baba Fooka
    Nov 7 at 12:15













up vote
0
down vote










up vote
0
down vote









Not too clever (hint: performance issue, but - see if it helps. Might be OK if there aren't too many rows involved.



You need lines 21 onwards.



I set similarity to be greater than 80 - adjust it, if needed (which is very probable, as data you posted is really sample data).



SQL> WITH ta (name)
2 AS (SELECT 'ABC' FROM DUAL
3 UNION ALL
4 SELECT 'DEE' FROM DUAL
5 UNION ALL
6 SELECT 'GHI' FROM DUAL
7 UNION ALL
8 SELECT 'JKL' FROM DUAL),
9 tb (name)
10 AS (SELECT 'ABC' FROM DUAL
11 UNION ALL
12 SELECT 'DEF' FROM DUAL
13 UNION ALL
14 SELECT 'GHI' FROM DUAL
15 UNION ALL
16 SELECT 'JKL' FROM DUAL
17 UNION ALL
18 SELECT 'MNO' FROM DUAL
19 UNION ALL
20 SELECT 'PQR' FROM DUAL)
21 SELECT ta.name,
22 tb.name,
23 UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) sim
24 FROM ta, tb
25 WHERE UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) > 80
26 ;

NAM NAM SIM
--- --- ----------
ABC ABC 100
DEE DEF 82
GHI GHI 100
JKL JKL 100

SQL>





share|improve this answer












Not too clever (hint: performance issue, but - see if it helps. Might be OK if there aren't too many rows involved.



You need lines 21 onwards.



I set similarity to be greater than 80 - adjust it, if needed (which is very probable, as data you posted is really sample data).



SQL> WITH ta (name)
2 AS (SELECT 'ABC' FROM DUAL
3 UNION ALL
4 SELECT 'DEE' FROM DUAL
5 UNION ALL
6 SELECT 'GHI' FROM DUAL
7 UNION ALL
8 SELECT 'JKL' FROM DUAL),
9 tb (name)
10 AS (SELECT 'ABC' FROM DUAL
11 UNION ALL
12 SELECT 'DEF' FROM DUAL
13 UNION ALL
14 SELECT 'GHI' FROM DUAL
15 UNION ALL
16 SELECT 'JKL' FROM DUAL
17 UNION ALL
18 SELECT 'MNO' FROM DUAL
19 UNION ALL
20 SELECT 'PQR' FROM DUAL)
21 SELECT ta.name,
22 tb.name,
23 UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) sim
24 FROM ta, tb
25 WHERE UTL_MATCH.jaro_winkler_similarity (ta.name, tb.name) > 80
26 ;

NAM NAM SIM
--- --- ----------
ABC ABC 100
DEE DEF 82
GHI GHI 100
JKL JKL 100

SQL>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 11:41









Littlefoot

18.1k51333




18.1k51333












  • With a little change its what i want but you are right performance is a concern using this.
    – Baba Fooka
    Nov 7 at 12:15


















  • With a little change its what i want but you are right performance is a concern using this.
    – Baba Fooka
    Nov 7 at 12:15
















With a little change its what i want but you are right performance is a concern using this.
– Baba Fooka
Nov 7 at 12:15




With a little change its what i want but you are right performance is a concern using this.
– Baba Fooka
Nov 7 at 12:15


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188266%2fselect-matching-string-from-another-table-oracle%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()