Link to home
Start Free TrialLog in
Avatar of austinfx
austinfx

asked on

Help with Join

Hello I need to query a table. I have to get two users names but I have the ID's from the lead_users table ..
I want to show each as their full name {first Last)

((Message table)) table name = simpleNote
id
senderID
recipientID
subject
message
status
dateCreateated  <-- MySQL Timestamp

((User table)) table name = leads_userInfo
userID
firstName
LastName



So I want to get a row that is like this:

FirstName LastName subject status date
Order by date

I want to do this with PHP PDO
Avatar of austinfx
austinfx

ASKER

I know I can do CONCAT(firstName, ' ', lastName) AS fullName.

How do I do this with two userID's in a joined query?
Avatar of hielo
Try:
SELECT CONCAT(B.firstName, B.lastName) as senderName, (SELECT CONCAT(firstName,' ', lastName) FROM `leads_userInfo` WHERE `userID`=A.recipientID LIMIT 1) as recipientName, A.`subject`, A.`status`, A.`dateCreated` as `date`
FROM simpleNote as A 
INNER JOIN leads_userInfo as B
ON A.senderID=B.userID

Open in new window

hielo This is so close! If the query was based on a record where simpleNote id =1 how  would this look?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Amazing !! Thank you!