NYCPHP Meetup

NYPHP.org

[nycphp-talk] MySQL - SQL Question

John Campbell jcampbell1 at gmail.com
Tue Apr 22 14:26:03 EDT 2008


On Tue, Apr 22, 2008 at 2:10 PM, Kenneth Dombrowski <kenneth at ylayali.net> wrote:
>  SELECT
>         p.id ,
>         p.price ,
>         IF(d.description, d.description, en.description) AS description ,
>         IF(d.lang_id, d.lang_id, en.lang_id) AS lang_id
>  FROM product AS p
>  INNER JOIN user AS u ON u.id = :1
>  LEFT JOIN description AS d ON (
>         d.product_id = p.id
>         AND d.lang_id = u.lang_id
>  )
>  LEFT JOIN description AS en ON (
>         en.product_id = p.id
>         AND d.lang_id = 'en'
>  )
>  WHERE p.category = :2

That is perfect... I feel dumb now.

Is there any reason IF is preferable to COALESCE?

Regards,
John Campbell



More information about the talk mailing list