tags:

views:

42

answers:

1

I have this sql query:

SELECT
S.SEARCH,
S.STATUS,
C.TITLE AS CategoryName,
E.SEARCH_ENGINES AS Engine,
S.RESULTS,
S.DATE,
S.TOTAL_RESULTS AS Total,
S.ID

FROM
PLD_SEARCHES AS S
Join PLD_CATEGORY AS C ON C.ID = S.CATEGORY_ID
Join PLD_SEARCH_ENGINES AS E ON S.SEARCH_ENGINES_ID = E.ID
ORDER BY S.DATE ASC

I want to identify if S.STATUS is either 1 or 0 and according to those values to return COMPLETE or PENDING in the query results

+3  A: 
SELECT S.SEARCH, if(S.STATUS=1,'COMPLETE','PENDING') as STATUS, 
C.TITLE AS CategoryName, E.SEARCH_ENGINES AS Engine, S.RESULTS, 
S.DATE, S.TOTAL_RESULTS AS Total, S.ID
FROM PLD_SEARCHES AS S 
Join PLD_CATEGORY AS C ON C.ID = S.CATEGORY_ID 
Join PLD_SEARCH_ENGINES AS E ON S.SEARCH_ENGINES_ID = E.ID 
ORDER BY S.DATE ASC

The IF function is if(x=y, TRUE RESULT, FALSE RESULT)

if(S.STATUS=1,'COMPLETE','PENDING')
Andy
Does it work with == ? Isn't it only one = ?
Leniel Macaferi
@Leneil typo updated :)
Andy
it works, thank you
Another typo in my name... :)
Leniel Macaferi
Lol sorry about that Leniel! NP userX :)
Andy