Here's my query:
$sql = "SELECT u.PHONE , u.STATE , if (uo.CHANNEL='','web',channel) as TYPE FROM user
LEFT JOIN user_oferts uo ON u.PHONE=uo.PHE_USER
WHERE (u.STATE='active') ";
And it is working great, I get what I want BUT for channel that is empty.
I need channel to be "web" if it is not "wap", this way channel will not be empty or null or nothing. How can I do that? What am I doing wrong?
Thanks a lot
select
...
case when channel = '' then
web
else
channel
end as TYPE....
using the CASE statement.
i.e. for your case
$sql = "SELECT u.PHONE , u.STATE
, case when coalesce(uo.CHANNEL, '') = '' then 'web' else channel end as TYPE
FROM user
LEFT JOIN user_oferts uo ON u.PHONE=uo.PHE_USER
WHERE (u.STATE='active') ";
Edit: added coalesce
to deal with possible NULL
values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With