# Am I using this "IF" function right?

**URL:** <https://forum.kirupa.com/t/am-i-using-this-if-function-right/302593>\
**Category:** programming\
**Created:** [January 4, 2010, 2:12am UTC](https://forum.kirupa.com/t/am-i-using-this-if-function-right/302593 "2010-01-04T02:12:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![IQAndreas](https://avatars.discourse-cdn.com/v4/letter/i/f08c70/32.png) [@IQAndreas](https://forum.kirupa.com/u/IQAndreas)\
**Post date:** [January 4, 2010, 2:12am UTC](https://forum.kirupa.com/t/am-i-using-this-if-function-right/302593/1 "2010-01-04T02:12:56Z")

</div>

If not, please correct. It looks good to me…

```auto
SELECT b.id AS id, 
        b.category_type AS category_type, 
        IF(b.category_type = 0, b.name, c.name) AS name ";
FROM `# __budget_categories` AS b, `#__ k2_categories` AS c ";
WHERE (b.user_id='".$userID."') ";
AND (b.category_type = c.id); ";

```

Basically, the category type can either have a value of zero, then the regular budget\_category’s name field will do. Or, if the category type is not zero, then the code should instead look in the k2\_categories for the name.

Understand?
