Replacing the missing values of while comparing 2 tables
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
add a comment |
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
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
add a comment |
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
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
python sql pandas python-2.7 sqlite
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
## 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
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
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%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
## 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
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
add a comment |
## 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
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
add a comment |
## 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
## 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
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
add a comment |
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
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%2f53424458%2freplacing-the-missing-values-of-while-comparing-2-tables%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
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