Reputation:
I have the following query:
$result = query("SELECT IdUser, followingID FROM following WHERE IdUser = '%d' AND followingID = '%d'", $id, $followingID);
I was wondering how I would return if the result is YES or NO based off the 0 and 1 count for if the relationship exists?
Upvotes: 0
Views: 125
Reputation: 1269443
Here is one way:
select (case when exists (SELECT IdUser, followingID
FROM following
WHERE IdUser = '%d' AND followingID = '%d'
)
then 'YES' else 'NO'
end) as YesOrNo
, $id, $followingID
Upvotes: 1