Replacing the missing values of while comparing 2 tables












0















I have 2 tables on my database and would like to compare both the tables and replace the missing values from one table to another. For example.



TABLE 1
column 1 column 2
ab 3
ab -
a 1
a -
b -
b 2
ab 3
ab -
a 1
a -
b 2

TABLE 2
column 1 column 2
ab 3
a 1
b 2


I want to compare both the tables on column 1 and replace only the missing values on column 2 and not touch the values that are already there.
Is this possible on SQL or using pandas on python? Any solution would be helpful.










share|improve this question




















  • 1





    Consider table 1 as the master and table 2 as the loop up table. All I wanted to do was to look up table 1 and replace the significant values on table 1. There are not always 2 rows of every thing. I have edited that bit. To give you more context table 1 has a few million rows and table 2 has the look ups for them. Please do let me know if this answers your questions.

    – Matt
    Nov 22 '18 at 11:20











  • Makes sense - I think the two answers below will achieve that.

    – DaveyDaveDave
    Nov 22 '18 at 11:27
















0















I have 2 tables on my database and would like to compare both the tables and replace the missing values from one table to another. For example.



TABLE 1
column 1 column 2
ab 3
ab -
a 1
a -
b -
b 2
ab 3
ab -
a 1
a -
b 2

TABLE 2
column 1 column 2
ab 3
a 1
b 2


I want to compare both the tables on column 1 and replace only the missing values on column 2 and not touch the values that are already there.
Is this possible on SQL or using pandas on python? Any solution would be helpful.










share|improve this question




















  • 1





    Consider table 1 as the master and table 2 as the loop up table. All I wanted to do was to look up table 1 and replace the significant values on table 1. There are not always 2 rows of every thing. I have edited that bit. To give you more context table 1 has a few million rows and table 2 has the look ups for them. Please do let me know if this answers your questions.

    – Matt
    Nov 22 '18 at 11:20











  • Makes sense - I think the two answers below will achieve that.

    – DaveyDaveDave
    Nov 22 '18 at 11:27














0












0








0








I have 2 tables on my database and would like to compare both the tables and replace the missing values from one table to another. For example.



TABLE 1
column 1 column 2
ab 3
ab -
a 1
a -
b -
b 2
ab 3
ab -
a 1
a -
b 2

TABLE 2
column 1 column 2
ab 3
a 1
b 2


I want to compare both the tables on column 1 and replace only the missing values on column 2 and not touch the values that are already there.
Is this possible on SQL or using pandas on python? Any solution would be helpful.










share|improve this question
















I have 2 tables on my database and would like to compare both the tables and replace the missing values from one table to another. For example.



TABLE 1
column 1 column 2
ab 3
ab -
a 1
a -
b -
b 2
ab 3
ab -
a 1
a -
b 2

TABLE 2
column 1 column 2
ab 3
a 1
b 2


I want to compare both the tables on column 1 and replace only the missing values on column 2 and not touch the values that are already there.
Is this possible on SQL or using pandas on python? Any solution would be helpful.







python sql pandas python-2.7 sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 11:14







Matt

















asked Nov 22 '18 at 5:34









MattMatt

546




546








  • 1





    Consider table 1 as the master and table 2 as the loop up table. All I wanted to do was to look up table 1 and replace the significant values on table 1. There are not always 2 rows of every thing. I have edited that bit. To give you more context table 1 has a few million rows and table 2 has the look ups for them. Please do let me know if this answers your questions.

    – Matt
    Nov 22 '18 at 11:20











  • Makes sense - I think the two answers below will achieve that.

    – DaveyDaveDave
    Nov 22 '18 at 11:27














  • 1





    Consider table 1 as the master and table 2 as the loop up table. All I wanted to do was to look up table 1 and replace the significant values on table 1. There are not always 2 rows of every thing. I have edited that bit. To give you more context table 1 has a few million rows and table 2 has the look ups for them. Please do let me know if this answers your questions.

    – Matt
    Nov 22 '18 at 11:20











  • Makes sense - I think the two answers below will achieve that.

    – DaveyDaveDave
    Nov 22 '18 at 11:27








1




1





Consider table 1 as the master and table 2 as the loop up table. All I wanted to do was to look up table 1 and replace the significant values on table 1. There are not always 2 rows of every thing. I have edited that bit. To give you more context table 1 has a few million rows and table 2 has the look ups for them. Please do let me know if this answers your questions.

– Matt
Nov 22 '18 at 11:20





Consider table 1 as the master and table 2 as the loop up table. All I wanted to do was to look up table 1 and replace the significant values on table 1. There are not always 2 rows of every thing. I have edited that bit. To give you more context table 1 has a few million rows and table 2 has the look ups for them. Please do let me know if this answers your questions.

– Matt
Nov 22 '18 at 11:20













Makes sense - I think the two answers below will achieve that.

– DaveyDaveDave
Nov 22 '18 at 11:27





Makes sense - I think the two answers below will achieve that.

– DaveyDaveDave
Nov 22 '18 at 11:27












1 Answer
1






active

oldest

votes


















-2














## SQL Query be like ##


This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL.



UPDATE table1
SET table1.Col2=table2.Col2
FROM table1
JOIN table2
ON table1.col1=table2.col1
where table1.col2 IS NULL





share|improve this answer


























  • Please add some context.

    – Matthieu Brucher
    Nov 22 '18 at 10:18











  • This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL. @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 22 '18 at 11:28











  • Please put this in your answer. It should be self-consistent.

    – Matthieu Brucher
    Nov 22 '18 at 11:51











  • Would you know how you would write it in sqlite? @Md.MehediHassan

    – Matt
    Nov 22 '18 at 13:19













  • Sorry buddy, I'm not working in sqlite yet @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 25 '18 at 4:01











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%2f53424458%2freplacing-the-missing-values-of-while-comparing-2-tables%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









-2














## SQL Query be like ##


This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL.



UPDATE table1
SET table1.Col2=table2.Col2
FROM table1
JOIN table2
ON table1.col1=table2.col1
where table1.col2 IS NULL





share|improve this answer


























  • Please add some context.

    – Matthieu Brucher
    Nov 22 '18 at 10:18











  • This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL. @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 22 '18 at 11:28











  • Please put this in your answer. It should be self-consistent.

    – Matthieu Brucher
    Nov 22 '18 at 11:51











  • Would you know how you would write it in sqlite? @Md.MehediHassan

    – Matt
    Nov 22 '18 at 13:19













  • Sorry buddy, I'm not working in sqlite yet @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 25 '18 at 4:01
















-2














## SQL Query be like ##


This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL.



UPDATE table1
SET table1.Col2=table2.Col2
FROM table1
JOIN table2
ON table1.col1=table2.col1
where table1.col2 IS NULL





share|improve this answer


























  • Please add some context.

    – Matthieu Brucher
    Nov 22 '18 at 10:18











  • This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL. @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 22 '18 at 11:28











  • Please put this in your answer. It should be self-consistent.

    – Matthieu Brucher
    Nov 22 '18 at 11:51











  • Would you know how you would write it in sqlite? @Md.MehediHassan

    – Matt
    Nov 22 '18 at 13:19













  • Sorry buddy, I'm not working in sqlite yet @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 25 '18 at 4:01














-2












-2








-2







## SQL Query be like ##


This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL.



UPDATE table1
SET table1.Col2=table2.Col2
FROM table1
JOIN table2
ON table1.col1=table2.col1
where table1.col2 IS NULL





share|improve this answer















## SQL Query be like ##


This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL.



UPDATE table1
SET table1.Col2=table2.Col2
FROM table1
JOIN table2
ON table1.col1=table2.col1
where table1.col2 IS NULL






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 4:00

























answered Nov 22 '18 at 9:00









Md. Mehedi HassanMd. Mehedi Hassan

176




176













  • Please add some context.

    – Matthieu Brucher
    Nov 22 '18 at 10:18











  • This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL. @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 22 '18 at 11:28











  • Please put this in your answer. It should be self-consistent.

    – Matthieu Brucher
    Nov 22 '18 at 11:51











  • Would you know how you would write it in sqlite? @Md.MehediHassan

    – Matt
    Nov 22 '18 at 13:19













  • Sorry buddy, I'm not working in sqlite yet @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 25 '18 at 4:01



















  • Please add some context.

    – Matthieu Brucher
    Nov 22 '18 at 10:18











  • This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL. @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 22 '18 at 11:28











  • Please put this in your answer. It should be self-consistent.

    – Matthieu Brucher
    Nov 22 '18 at 11:51











  • Would you know how you would write it in sqlite? @Md.MehediHassan

    – Matt
    Nov 22 '18 at 13:19













  • Sorry buddy, I'm not working in sqlite yet @MatthieuBrucher

    – Md. Mehedi Hassan
    Nov 25 '18 at 4:01

















Please add some context.

– Matthieu Brucher
Nov 22 '18 at 10:18





Please add some context.

– Matthieu Brucher
Nov 22 '18 at 10:18













This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL. @MatthieuBrucher

– Md. Mehedi Hassan
Nov 22 '18 at 11:28





This query replaces the column2 value of Table2 to the column2 of Table1 which are NULL. @MatthieuBrucher

– Md. Mehedi Hassan
Nov 22 '18 at 11:28













Please put this in your answer. It should be self-consistent.

– Matthieu Brucher
Nov 22 '18 at 11:51





Please put this in your answer. It should be self-consistent.

– Matthieu Brucher
Nov 22 '18 at 11:51













Would you know how you would write it in sqlite? @Md.MehediHassan

– Matt
Nov 22 '18 at 13:19







Would you know how you would write it in sqlite? @Md.MehediHassan

– Matt
Nov 22 '18 at 13:19















Sorry buddy, I'm not working in sqlite yet @MatthieuBrucher

– Md. Mehedi Hassan
Nov 25 '18 at 4:01





Sorry buddy, I'm not working in sqlite yet @MatthieuBrucher

– Md. Mehedi Hassan
Nov 25 '18 at 4:01


















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%2f53424458%2freplacing-the-missing-values-of-while-comparing-2-tables%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

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'