Query to add a column depending of outcome of there columns
Posted
by Tam
on Stack Overflow
See other posts from Stack Overflow
or by Tam
Published on 2010-03-28T07:19:55Z
Indexed on
2010/03/28
7:23 UTC
Read the original article
Hit count: 201
I have a user table 'users' that has fields like:
id
first_name
last_name
...
and have another table that determines relationships:
user_id
friend_id
user_accepted
friend_accepted
....
I would like to generate a query that selects all the users but also add another field/column say 'network_status' that depends on the values of user_accepted and fiend_accepted. For example, if user_accepted is true friend_accepted is false I want the 'network_status' field to say 'request sent'. Can I possibly do this in one query? (I would prefer not to user if/else inside the query but if that's the only way so be it)
© Stack Overflow or respective owner