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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -