I have the following SQL which creates a friends list with other info:
SELECT DISTINCT exchange.id userid, exchange.name username, exchange.lastactivity lastactivity, exchange.id avatar, exchange.id link, cometchat_status.message, cometchat_status.status
FROM buddy
JOIN exchange ON buddy.penpalA = exchange.id
LEFT JOIN cometchat_status ON exchange.id = cometchat_status.userid
WHERE buddy.penpalB =887
ORDER BY username ASC
It works fine for displaying a list of someones friends where the current member is penpalA, however I want to make it so that it also checks to see if penpalB is the current member and if so takes the info from that column and not the other one as either penpalA or penpalB could be the current member and it currently isnt checking this.
How can i modify it so it works?
Do you have any field which is set to some value which defines whether something is set to current or not??For e.g suppose you have one of the field in the database table named “current” the value can be 0 or 1 only.0 if its not current and 1 if its current.
Now in the query you can add WHERE current=’1′ and based on that extract the corresponding fields you want from the database.