Database Join - Right Join?
I have two tables shown below
Table 1 :
Table 2 :
I am looking for a join that would result in a table like this
Result :
Any help is highly appreciated
database join
add a comment |
I have two tables shown below
Table 1 :
Table 2 :
I am looking for a join that would result in a table like this
Result :
Any help is highly appreciated
database join
Hi. Please read & act on How to Ask, the downvote arrow mouseover text & hits googling 'stackexchange homework'. Show what parts you can do & explain how you are stuck. Minimal, Complete, and Verifiable example Now you are just asking us to do your homework for you. PS Please use text, not images/links, for text (including code, tables & ERDs). Use a link/image only for convenience to supplement text and/or for what cannot be given in text. And never give a diagram without a legend/key. Use edit functions to inline, not links, if you have the rep--make your post self-contained.
– philipxy
Nov 14 '18 at 5:13
2
We can't really give you a query without knowing why the first record only selectively joins to one of the two phone number records. Unclear what you are asking here.
– Tim Biegeleisen
Nov 14 '18 at 5:14
1
In addition to Tim's question - what rdbms are you using?
– Mureinik
Nov 14 '18 at 6:20
@ZainFarooq Please do not inline links inappropriately. See my comment above re using text whenever possible. Either replace a link to a table by code block formatted tabular text (which should simultaneously be code to create & initialize a table if the question should give a Minimal, Complete, and Verifiable example) or, much better, comment to tell the poster to do it. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted.
– philipxy
Nov 14 '18 at 7:05
provide the code that you have already tried. It is not clear how to answer this question
– Nishil
Nov 14 '18 at 8:53
add a comment |
I have two tables shown below
Table 1 :
Table 2 :
I am looking for a join that would result in a table like this
Result :
Any help is highly appreciated
database join
I have two tables shown below
Table 1 :
Table 2 :
I am looking for a join that would result in a table like this
Result :
Any help is highly appreciated
database join
database join
edited Nov 14 '18 at 6:07
Zain Farooq
1,9942928
1,9942928
asked Nov 14 '18 at 5:10
Omkar KhareOmkar Khare
1
1
Hi. Please read & act on How to Ask, the downvote arrow mouseover text & hits googling 'stackexchange homework'. Show what parts you can do & explain how you are stuck. Minimal, Complete, and Verifiable example Now you are just asking us to do your homework for you. PS Please use text, not images/links, for text (including code, tables & ERDs). Use a link/image only for convenience to supplement text and/or for what cannot be given in text. And never give a diagram without a legend/key. Use edit functions to inline, not links, if you have the rep--make your post self-contained.
– philipxy
Nov 14 '18 at 5:13
2
We can't really give you a query without knowing why the first record only selectively joins to one of the two phone number records. Unclear what you are asking here.
– Tim Biegeleisen
Nov 14 '18 at 5:14
1
In addition to Tim's question - what rdbms are you using?
– Mureinik
Nov 14 '18 at 6:20
@ZainFarooq Please do not inline links inappropriately. See my comment above re using text whenever possible. Either replace a link to a table by code block formatted tabular text (which should simultaneously be code to create & initialize a table if the question should give a Minimal, Complete, and Verifiable example) or, much better, comment to tell the poster to do it. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted.
– philipxy
Nov 14 '18 at 7:05
provide the code that you have already tried. It is not clear how to answer this question
– Nishil
Nov 14 '18 at 8:53
add a comment |
Hi. Please read & act on How to Ask, the downvote arrow mouseover text & hits googling 'stackexchange homework'. Show what parts you can do & explain how you are stuck. Minimal, Complete, and Verifiable example Now you are just asking us to do your homework for you. PS Please use text, not images/links, for text (including code, tables & ERDs). Use a link/image only for convenience to supplement text and/or for what cannot be given in text. And never give a diagram without a legend/key. Use edit functions to inline, not links, if you have the rep--make your post self-contained.
– philipxy
Nov 14 '18 at 5:13
2
We can't really give you a query without knowing why the first record only selectively joins to one of the two phone number records. Unclear what you are asking here.
– Tim Biegeleisen
Nov 14 '18 at 5:14
1
In addition to Tim's question - what rdbms are you using?
– Mureinik
Nov 14 '18 at 6:20
@ZainFarooq Please do not inline links inappropriately. See my comment above re using text whenever possible. Either replace a link to a table by code block formatted tabular text (which should simultaneously be code to create & initialize a table if the question should give a Minimal, Complete, and Verifiable example) or, much better, comment to tell the poster to do it. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted.
– philipxy
Nov 14 '18 at 7:05
provide the code that you have already tried. It is not clear how to answer this question
– Nishil
Nov 14 '18 at 8:53
Hi. Please read & act on How to Ask, the downvote arrow mouseover text & hits googling 'stackexchange homework'. Show what parts you can do & explain how you are stuck. Minimal, Complete, and Verifiable example Now you are just asking us to do your homework for you. PS Please use text, not images/links, for text (including code, tables & ERDs). Use a link/image only for convenience to supplement text and/or for what cannot be given in text. And never give a diagram without a legend/key. Use edit functions to inline, not links, if you have the rep--make your post self-contained.
– philipxy
Nov 14 '18 at 5:13
Hi. Please read & act on How to Ask, the downvote arrow mouseover text & hits googling 'stackexchange homework'. Show what parts you can do & explain how you are stuck. Minimal, Complete, and Verifiable example Now you are just asking us to do your homework for you. PS Please use text, not images/links, for text (including code, tables & ERDs). Use a link/image only for convenience to supplement text and/or for what cannot be given in text. And never give a diagram without a legend/key. Use edit functions to inline, not links, if you have the rep--make your post self-contained.
– philipxy
Nov 14 '18 at 5:13
2
2
We can't really give you a query without knowing why the first record only selectively joins to one of the two phone number records. Unclear what you are asking here.
– Tim Biegeleisen
Nov 14 '18 at 5:14
We can't really give you a query without knowing why the first record only selectively joins to one of the two phone number records. Unclear what you are asking here.
– Tim Biegeleisen
Nov 14 '18 at 5:14
1
1
In addition to Tim's question - what rdbms are you using?
– Mureinik
Nov 14 '18 at 6:20
In addition to Tim's question - what rdbms are you using?
– Mureinik
Nov 14 '18 at 6:20
@ZainFarooq Please do not inline links inappropriately. See my comment above re using text whenever possible. Either replace a link to a table by code block formatted tabular text (which should simultaneously be code to create & initialize a table if the question should give a Minimal, Complete, and Verifiable example) or, much better, comment to tell the poster to do it. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted.
– philipxy
Nov 14 '18 at 7:05
@ZainFarooq Please do not inline links inappropriately. See my comment above re using text whenever possible. Either replace a link to a table by code block formatted tabular text (which should simultaneously be code to create & initialize a table if the question should give a Minimal, Complete, and Verifiable example) or, much better, comment to tell the poster to do it. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted.
– philipxy
Nov 14 '18 at 7:05
provide the code that you have already tried. It is not clear how to answer this question
– Nishil
Nov 14 '18 at 8:53
provide the code that you have already tried. It is not clear how to answer this question
– Nishil
Nov 14 '18 at 8:53
add a comment |
1 Answer
1
active
oldest
votes
You can do it using LEFT JOIN
SELECT t2.Employee_ID,t1.Name,t1.Id,t2.Area_Code,t2.Phone_Number FROM dbo.Table_2 t2
LEFT JOIN dbo.Table_1 t1 ON t1.Employee_ID=t2.Employee_ID
That query does not give the requested result. See the comments on the question. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted. If it weren't a faq or unclear it should be downvoted & closed for not having a Minimal, Complete, and Verifiable example--if it had one, you could have run your query & seen it was wrong.
– philipxy
Nov 14 '18 at 7:09
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%2f53293538%2fdatabase-join-right-join%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
You can do it using LEFT JOIN
SELECT t2.Employee_ID,t1.Name,t1.Id,t2.Area_Code,t2.Phone_Number FROM dbo.Table_2 t2
LEFT JOIN dbo.Table_1 t1 ON t1.Employee_ID=t2.Employee_ID
That query does not give the requested result. See the comments on the question. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted. If it weren't a faq or unclear it should be downvoted & closed for not having a Minimal, Complete, and Verifiable example--if it had one, you could have run your query & seen it was wrong.
– philipxy
Nov 14 '18 at 7:09
add a comment |
You can do it using LEFT JOIN
SELECT t2.Employee_ID,t1.Name,t1.Id,t2.Area_Code,t2.Phone_Number FROM dbo.Table_2 t2
LEFT JOIN dbo.Table_1 t1 ON t1.Employee_ID=t2.Employee_ID
That query does not give the requested result. See the comments on the question. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted. If it weren't a faq or unclear it should be downvoted & closed for not having a Minimal, Complete, and Verifiable example--if it had one, you could have run your query & seen it was wrong.
– philipxy
Nov 14 '18 at 7:09
add a comment |
You can do it using LEFT JOIN
SELECT t2.Employee_ID,t1.Name,t1.Id,t2.Area_Code,t2.Phone_Number FROM dbo.Table_2 t2
LEFT JOIN dbo.Table_1 t1 ON t1.Employee_ID=t2.Employee_ID
You can do it using LEFT JOIN
SELECT t2.Employee_ID,t1.Name,t1.Id,t2.Area_Code,t2.Phone_Number FROM dbo.Table_2 t2
LEFT JOIN dbo.Table_1 t1 ON t1.Employee_ID=t2.Employee_ID
answered Nov 14 '18 at 6:42
Sabir Al FatehSabir Al Fateh
96121121
96121121
That query does not give the requested result. See the comments on the question. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted. If it weren't a faq or unclear it should be downvoted & closed for not having a Minimal, Complete, and Verifiable example--if it had one, you could have run your query & seen it was wrong.
– philipxy
Nov 14 '18 at 7:09
add a comment |
That query does not give the requested result. See the comments on the question. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted. If it weren't a faq or unclear it should be downvoted & closed for not having a Minimal, Complete, and Verifiable example--if it had one, you could have run your query & seen it was wrong.
– philipxy
Nov 14 '18 at 7:09
That query does not give the requested result. See the comments on the question. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted. If it weren't a faq or unclear it should be downvoted & closed for not having a Minimal, Complete, and Verifiable example--if it had one, you could have run your query & seen it was wrong.
– philipxy
Nov 14 '18 at 7:09
That query does not give the requested result. See the comments on the question. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted. If it weren't a faq or unclear it should be downvoted & closed for not having a Minimal, Complete, and Verifiable example--if it had one, you could have run your query & seen it was wrong.
– philipxy
Nov 14 '18 at 7:09
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%2f53293538%2fdatabase-join-right-join%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
Hi. Please read & act on How to Ask, the downvote arrow mouseover text & hits googling 'stackexchange homework'. Show what parts you can do & explain how you are stuck. Minimal, Complete, and Verifiable example Now you are just asking us to do your homework for you. PS Please use text, not images/links, for text (including code, tables & ERDs). Use a link/image only for convenience to supplement text and/or for what cannot be given in text. And never give a diagram without a legend/key. Use edit functions to inline, not links, if you have the rep--make your post self-contained.
– philipxy
Nov 14 '18 at 5:13
2
We can't really give you a query without knowing why the first record only selectively joins to one of the two phone number records. Unclear what you are asking here.
– Tim Biegeleisen
Nov 14 '18 at 5:14
1
In addition to Tim's question - what rdbms are you using?
– Mureinik
Nov 14 '18 at 6:20
@ZainFarooq Please do not inline links inappropriately. See my comment above re using text whenever possible. Either replace a link to a table by code block formatted tabular text (which should simultaneously be code to create & initialize a table if the question should give a Minimal, Complete, and Verifiable example) or, much better, comment to tell the poster to do it. PS This is unclear so should not be answered; it should be downvoted & close voted. When it's clear it will be a faq; it should be downvoted & close voted.
– philipxy
Nov 14 '18 at 7:05
provide the code that you have already tried. It is not clear how to answer this question
– Nishil
Nov 14 '18 at 8:53