subquery - IF..ELSE-statement in SQL SELECT? -
i'm trying make user activity feed displays users' activities friends of logged-in user.
the fields user1 , user2 friend request sender , friend request receiver. problem logged-in user in either field i'm wondering how can make if..else
statement particular issue.
basically want:
if user2 $log_username select user1 friends... else select user2 friends.
the boldfaced code(subquery) 1 i'm referring specifically.
$sql = " select * status author in ( select user2 friends user1='$log_username' , accepted='1' or user2='$log_username' , accepted='1' ) , type='a' ";
any appreciated.
the if
within sql statement case
. (not sure if gives want demonstrate concept).
$sql = " select * status author in ( select case when user2 = '$log_username' user1 else user2 end friends user1='$log_username' , accepted='1' or user2='$log_username' , accepted='1' ) , type='a' ";
Comments
Post a Comment