Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to use a name for 2 seperate columns.

What I had is working below. But this only shows the first name/last name for the person who has declared a tip.

I want to be able to concat the first name and last name and use that where dt.last_modified_user_id is. Would this be a seperate select statement?

I used to use sql server and would be able to do this via a query editor - but I'm now trying to use MySQL so I'm a little buffedled.

What I have tried:

select dt.declare_time, p.first_name, p.last_name, dt.amount, dt.last_modified_time, dt.Last_Modified_User_ID from declared_tip dt
join person p on dt.person_id = p.id
Posted
Updated 22-Feb-17 7:49am
Comments
Bryian Tan 10-Feb-17 9:35am    
any error messages?
Karthik_Mahalingam 10-Feb-17 9:47am    
what is your expected output
Mendaharin 10-Feb-17 9:54am    
I'm not getting any error messages. It's just the current output.

What I'm trying to achieve is the following column headings.

declare time | First_Name | Last_name | Amount | Last_modified_time | Name of modifier (dt.last_modified_user_ID)

the name comes from the same person table (person)
Karthik_Mahalingam 12-Feb-17 6:08am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

1 solution

You'll need to join to another instance of the person table. You can do this in SQL by using a table alias in your JOIN clause.

SELECT dt.declare_time,
p.first_name,
p.last_name,
dt.amount,
dt.last_modified_time,
dt.Last_Modified_User_ID,
dtp.first_name,
dtp.last_name
FROM declared_tip dt
JOIN person p ON dt.person_id = p.id
JOIN person dtp ON dt.Last_Modified_User_ID = dtp.id


Note the "dtp" fields at the end of the SELECT. If you want to concatenate them, you can, but this will show them as separate fields.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900