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
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
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
ASKER
hielo This is so close! If the query was based on a record where simpleNote id =1 how would this look?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Amazing !! Thank you!
ASKER
How do I do this with two userID's in a joined query?