How can I use a mySQL SELECT IF statement row to JOIN another table?

前端 未结 1 672
灰色年华
灰色年华 2021-01-16 00:40

I am using an IF statement in my mySQL SELECT statement and depending on the returned result from the IF statement I would like to join another table.

Eg. SELECT nam

相关标签:
1条回答
  • 2021-01-16 01:29

    You will have to duplicate the IF call there. For example:

    SELECT
        name,
        IF(apple = 'brown', color1, color2) AS ripeness
    FROM
        apples
        JOIN apple_type ON apple_type.color = IF(apple = 'brown', color1, color2)
    
    0 讨论(0)
提交回复
热议问题