I am making a get friends network function using SQL. I used the following code:
SELECT relationship.requester,
relationship.requested,
user.firstname,
user.lastname
FROM relationship
JOIN user ON (user.guid = relationship.requester
OR user.guid = sqrelationship.requested)
WHERE relationship.requester = {$userid}
OR relationship.requested = {$userid}
AND relationship.approved = 1
The SQL will return a table with the IDs of approved relationships either initiated or received by user. However, the user.firstname and user.lastname return me only one set of results. How can I make this expression able to get both requester and requested’s names?
Hard to tell from the question where you don’t specify the design of your tables, but I’m guessing like this: