I have a table in which I want to retrieve the table as follow.

Login Name Parent User Email ID Mobile No
abc abc_parent abc@abc.com 9999999999


MySql Table as follow in tbl_users

user_id parent_user loginname email mobile
321 123 abc_parent abc@abc.com 9999999999
231 456 abc 123@123.com 8888888888

I am having issue as mentioned on the top, I am not able to retrieve the data for parent user as abc_parent, am able to achieve to get parent user id not the parent user loginname as all loginnames come in single column and ids come in first 2 columns.

How can I show the parent user loginname in place of parent_user id.

Currently, i use the following code.

SELECT * FROM tbl_users where status_id='2'

any help will be appreciated, thanks

Try this

SELECT user_id,parent_user,loginname,email,mobile
FROM tbl_users t1 where t1.status_id='2'
inner join tbl_users t2
on t2.user_id=t1.parent_user

hope it works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.