How do I display name instated of Id



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















I have two table Test1 and Test2.



Test1



p_id|imp_id | Name | Member_type 
1 |001 | A | 1
2 |002 | B | 2
3 |003 | C | 1
4 |004 | D | 2


Test2



r_id|p_id |secondary_type 
1 |1 |2
2 |3 |4


I am using join to get my design output.



Query



SELECT * FROM `test1` JOIN `test2` ON `test2`.`secondary_type` = `test1`.`p_id` 


My output is



p_id imp_id Name Member_type r_id p_id secondary_type 
2 002 B 2 1 1 2
4 004 D 2 2 3 4


So I am getting p_id value. I have to display name instated of the Id value.



For example B is connected to A. So I am getting the ID of A but I need Name instated of ID.



So my output will



p_id imp_id Name Member_type r_id | p_id| secondary_type 
2 002 B 2 1 | A | 2
4 004 D 2 2 | C | 4


I tried using CodeIgniter.



$this->db->select('*');
$this->db->from('test1');
$this->db->join('test2', 'test2.secondary_type = test1.p_id');









share|improve this question
























  • Just do: test1.name as p_id

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:33











  • Where I have to use this? in the query?

    – user9437856
    Nov 15 '18 at 11:34











  • Based on your sample data, where are you getting the value poikj for Name ?

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:35











  • @MadhurBhaiya, I added wrongly. I updated my question.

    – user9437856
    Nov 15 '18 at 17:54

















-2















I have two table Test1 and Test2.



Test1



p_id|imp_id | Name | Member_type 
1 |001 | A | 1
2 |002 | B | 2
3 |003 | C | 1
4 |004 | D | 2


Test2



r_id|p_id |secondary_type 
1 |1 |2
2 |3 |4


I am using join to get my design output.



Query



SELECT * FROM `test1` JOIN `test2` ON `test2`.`secondary_type` = `test1`.`p_id` 


My output is



p_id imp_id Name Member_type r_id p_id secondary_type 
2 002 B 2 1 1 2
4 004 D 2 2 3 4


So I am getting p_id value. I have to display name instated of the Id value.



For example B is connected to A. So I am getting the ID of A but I need Name instated of ID.



So my output will



p_id imp_id Name Member_type r_id | p_id| secondary_type 
2 002 B 2 1 | A | 2
4 004 D 2 2 | C | 4


I tried using CodeIgniter.



$this->db->select('*');
$this->db->from('test1');
$this->db->join('test2', 'test2.secondary_type = test1.p_id');









share|improve this question
























  • Just do: test1.name as p_id

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:33











  • Where I have to use this? in the query?

    – user9437856
    Nov 15 '18 at 11:34











  • Based on your sample data, where are you getting the value poikj for Name ?

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:35











  • @MadhurBhaiya, I added wrongly. I updated my question.

    – user9437856
    Nov 15 '18 at 17:54













-2












-2








-2








I have two table Test1 and Test2.



Test1



p_id|imp_id | Name | Member_type 
1 |001 | A | 1
2 |002 | B | 2
3 |003 | C | 1
4 |004 | D | 2


Test2



r_id|p_id |secondary_type 
1 |1 |2
2 |3 |4


I am using join to get my design output.



Query



SELECT * FROM `test1` JOIN `test2` ON `test2`.`secondary_type` = `test1`.`p_id` 


My output is



p_id imp_id Name Member_type r_id p_id secondary_type 
2 002 B 2 1 1 2
4 004 D 2 2 3 4


So I am getting p_id value. I have to display name instated of the Id value.



For example B is connected to A. So I am getting the ID of A but I need Name instated of ID.



So my output will



p_id imp_id Name Member_type r_id | p_id| secondary_type 
2 002 B 2 1 | A | 2
4 004 D 2 2 | C | 4


I tried using CodeIgniter.



$this->db->select('*');
$this->db->from('test1');
$this->db->join('test2', 'test2.secondary_type = test1.p_id');









share|improve this question
















I have two table Test1 and Test2.



Test1



p_id|imp_id | Name | Member_type 
1 |001 | A | 1
2 |002 | B | 2
3 |003 | C | 1
4 |004 | D | 2


Test2



r_id|p_id |secondary_type 
1 |1 |2
2 |3 |4


I am using join to get my design output.



Query



SELECT * FROM `test1` JOIN `test2` ON `test2`.`secondary_type` = `test1`.`p_id` 


My output is



p_id imp_id Name Member_type r_id p_id secondary_type 
2 002 B 2 1 1 2
4 004 D 2 2 3 4


So I am getting p_id value. I have to display name instated of the Id value.



For example B is connected to A. So I am getting the ID of A but I need Name instated of ID.



So my output will



p_id imp_id Name Member_type r_id | p_id| secondary_type 
2 002 B 2 1 | A | 2
4 004 D 2 2 | C | 4


I tried using CodeIgniter.



$this->db->select('*');
$this->db->from('test1');
$this->db->join('test2', 'test2.secondary_type = test1.p_id');






mysql phpmyadmin codeigniter-3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 12:12







user9437856

















asked Nov 15 '18 at 11:29









user9437856user9437856

471314




471314












  • Just do: test1.name as p_id

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:33











  • Where I have to use this? in the query?

    – user9437856
    Nov 15 '18 at 11:34











  • Based on your sample data, where are you getting the value poikj for Name ?

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:35











  • @MadhurBhaiya, I added wrongly. I updated my question.

    – user9437856
    Nov 15 '18 at 17:54

















  • Just do: test1.name as p_id

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:33











  • Where I have to use this? in the query?

    – user9437856
    Nov 15 '18 at 11:34











  • Based on your sample data, where are you getting the value poikj for Name ?

    – Chowkidar Madhur Bhaiya
    Nov 15 '18 at 11:35











  • @MadhurBhaiya, I added wrongly. I updated my question.

    – user9437856
    Nov 15 '18 at 17:54
















Just do: test1.name as p_id

– Chowkidar Madhur Bhaiya
Nov 15 '18 at 11:33





Just do: test1.name as p_id

– Chowkidar Madhur Bhaiya
Nov 15 '18 at 11:33













Where I have to use this? in the query?

– user9437856
Nov 15 '18 at 11:34





Where I have to use this? in the query?

– user9437856
Nov 15 '18 at 11:34













Based on your sample data, where are you getting the value poikj for Name ?

– Chowkidar Madhur Bhaiya
Nov 15 '18 at 11:35





Based on your sample data, where are you getting the value poikj for Name ?

– Chowkidar Madhur Bhaiya
Nov 15 '18 at 11:35













@MadhurBhaiya, I added wrongly. I updated my question.

– user9437856
Nov 15 '18 at 17:54





@MadhurBhaiya, I added wrongly. I updated my question.

– user9437856
Nov 15 '18 at 17:54












1 Answer
1






active

oldest

votes


















1














Try using alias in select statement like



SELECT 
test1.p_id,test1.imp_id,test2.name,test1.member_type,test2.r_id,test1.name as
p_id,test2.secondary_type
FROM `test1` JOIN `test2`
ON `test2`.`secondary_type` = `test1`.`p_id`


Result will come as per your requirement.






share|improve this answer

























  • Can you share the complete query? because I am not getting it.

    – user9437856
    Nov 15 '18 at 11:39











  • ok..let me edit answer

    – mukund
    Nov 15 '18 at 11:41











  • another thing p_id is duplicate ....I don't think that you want output like this

    – mukund
    Nov 15 '18 at 11:50











  • I am getting the error #1054 - Unknown column 'test2.name' in 'field list'

    – user9437856
    Nov 15 '18 at 11:58











  • there are no field related to name in test2 table....try test1.name

    – mukund
    Nov 15 '18 at 11:59












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%2f53318483%2fhow-do-i-display-name-instated-of-id%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









1














Try using alias in select statement like



SELECT 
test1.p_id,test1.imp_id,test2.name,test1.member_type,test2.r_id,test1.name as
p_id,test2.secondary_type
FROM `test1` JOIN `test2`
ON `test2`.`secondary_type` = `test1`.`p_id`


Result will come as per your requirement.






share|improve this answer

























  • Can you share the complete query? because I am not getting it.

    – user9437856
    Nov 15 '18 at 11:39











  • ok..let me edit answer

    – mukund
    Nov 15 '18 at 11:41











  • another thing p_id is duplicate ....I don't think that you want output like this

    – mukund
    Nov 15 '18 at 11:50











  • I am getting the error #1054 - Unknown column 'test2.name' in 'field list'

    – user9437856
    Nov 15 '18 at 11:58











  • there are no field related to name in test2 table....try test1.name

    – mukund
    Nov 15 '18 at 11:59
















1














Try using alias in select statement like



SELECT 
test1.p_id,test1.imp_id,test2.name,test1.member_type,test2.r_id,test1.name as
p_id,test2.secondary_type
FROM `test1` JOIN `test2`
ON `test2`.`secondary_type` = `test1`.`p_id`


Result will come as per your requirement.






share|improve this answer

























  • Can you share the complete query? because I am not getting it.

    – user9437856
    Nov 15 '18 at 11:39











  • ok..let me edit answer

    – mukund
    Nov 15 '18 at 11:41











  • another thing p_id is duplicate ....I don't think that you want output like this

    – mukund
    Nov 15 '18 at 11:50











  • I am getting the error #1054 - Unknown column 'test2.name' in 'field list'

    – user9437856
    Nov 15 '18 at 11:58











  • there are no field related to name in test2 table....try test1.name

    – mukund
    Nov 15 '18 at 11:59














1












1








1







Try using alias in select statement like



SELECT 
test1.p_id,test1.imp_id,test2.name,test1.member_type,test2.r_id,test1.name as
p_id,test2.secondary_type
FROM `test1` JOIN `test2`
ON `test2`.`secondary_type` = `test1`.`p_id`


Result will come as per your requirement.






share|improve this answer















Try using alias in select statement like



SELECT 
test1.p_id,test1.imp_id,test2.name,test1.member_type,test2.r_id,test1.name as
p_id,test2.secondary_type
FROM `test1` JOIN `test2`
ON `test2`.`secondary_type` = `test1`.`p_id`


Result will come as per your requirement.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 11:52









fa06

19.2k21019




19.2k21019










answered Nov 15 '18 at 11:38









mukundmukund

295




295












  • Can you share the complete query? because I am not getting it.

    – user9437856
    Nov 15 '18 at 11:39











  • ok..let me edit answer

    – mukund
    Nov 15 '18 at 11:41











  • another thing p_id is duplicate ....I don't think that you want output like this

    – mukund
    Nov 15 '18 at 11:50











  • I am getting the error #1054 - Unknown column 'test2.name' in 'field list'

    – user9437856
    Nov 15 '18 at 11:58











  • there are no field related to name in test2 table....try test1.name

    – mukund
    Nov 15 '18 at 11:59


















  • Can you share the complete query? because I am not getting it.

    – user9437856
    Nov 15 '18 at 11:39











  • ok..let me edit answer

    – mukund
    Nov 15 '18 at 11:41











  • another thing p_id is duplicate ....I don't think that you want output like this

    – mukund
    Nov 15 '18 at 11:50











  • I am getting the error #1054 - Unknown column 'test2.name' in 'field list'

    – user9437856
    Nov 15 '18 at 11:58











  • there are no field related to name in test2 table....try test1.name

    – mukund
    Nov 15 '18 at 11:59

















Can you share the complete query? because I am not getting it.

– user9437856
Nov 15 '18 at 11:39





Can you share the complete query? because I am not getting it.

– user9437856
Nov 15 '18 at 11:39













ok..let me edit answer

– mukund
Nov 15 '18 at 11:41





ok..let me edit answer

– mukund
Nov 15 '18 at 11:41













another thing p_id is duplicate ....I don't think that you want output like this

– mukund
Nov 15 '18 at 11:50





another thing p_id is duplicate ....I don't think that you want output like this

– mukund
Nov 15 '18 at 11:50













I am getting the error #1054 - Unknown column 'test2.name' in 'field list'

– user9437856
Nov 15 '18 at 11:58





I am getting the error #1054 - Unknown column 'test2.name' in 'field list'

– user9437856
Nov 15 '18 at 11:58













there are no field related to name in test2 table....try test1.name

– mukund
Nov 15 '18 at 11:59






there are no field related to name in test2 table....try test1.name

– mukund
Nov 15 '18 at 11:59




















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%2f53318483%2fhow-do-i-display-name-instated-of-id%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

Kleinkühnau

Makov (Slowakei)

Peter Parker: The Spectacular Spider-Man #308