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;
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
add a comment |
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
Just do:test1.nameasp_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 valuepoikjforName?
– Chowkidar Madhur Bhaiya
Nov 15 '18 at 11:35
@MadhurBhaiya, I added wrongly. I updated my question.
– user9437856
Nov 15 '18 at 17:54
add a comment |
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
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
mysql phpmyadmin codeigniter-3
edited Nov 15 '18 at 12:12
user9437856
asked Nov 15 '18 at 11:29
user9437856user9437856
471314
471314
Just do:test1.nameasp_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 valuepoikjforName?
– Chowkidar Madhur Bhaiya
Nov 15 '18 at 11:35
@MadhurBhaiya, I added wrongly. I updated my question.
– user9437856
Nov 15 '18 at 17:54
add a comment |
Just do:test1.nameasp_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 valuepoikjforName?
– 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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
|
show 3 more comments
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%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
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.
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
|
show 3 more comments
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.
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
|
show 3 more comments
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.
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.
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
|
show 3 more comments
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
|
show 3 more comments
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%2f53318483%2fhow-do-i-display-name-instated-of-id%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
Just do:
test1.nameasp_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
poikjforName?– Chowkidar Madhur Bhaiya
Nov 15 '18 at 11:35
@MadhurBhaiya, I added wrongly. I updated my question.
– user9437856
Nov 15 '18 at 17:54