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
austinfxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

How do I do this with two userID's in a joined query?
hieloCommented:
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

austinfxAuthor Commented:
hielo This is so close! If the query was based on a record where simpleNote id =1 how  would this look?
hieloCommented:
On the query above, "...simpleNote as A...", A becomes an alias for simpleNote.  So, add "...WHERE A.id=1" to the end of the query:

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
WHERE A.id=1

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
austinfxAuthor Commented:
Amazing !! Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.