Query Help - if(s.user_id <> NULL, 1, 0) not working as expected

dsrnu
dsrnu used Ask the Experts™
on
I'm trying to make s.user_id return 1 if it's not null, otherwise return 0.. but my code below seems to be returning all zeroes.. any ideas?
'SELECT u.id AS user_id, u.username, if(s.user_id <> NULL, 1, 0) AS is_seller FROM ' . $this->user_table_name . ' u LEFT JOIN ' . $this->seller_table_name . ' s ON u.id=s.user_id'

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hi again :)

Try it with IS NOT NULL instead of <>, so you get:

'SELECT u.id AS user_id, u.username, if(s.user_id IS NOT NULL, 1, 0) AS is_seller FROM ' . $this->user_table_name . ' u LEFT JOIN ' . $this->seller_table_name . ' s ON u.id=s.user_id'

Author

Commented:
you're awesome rubene! worked
Commented:
No problem you're welcome. :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial