MYSQL if a select query returns 0 rows then another select query?

前端 未结 7 1171
故里飘歌
故里飘歌 2020-12-03 18:01

if select * from table where x=1 returns 0 rows, then I need select * from table where x=2 [or some other query]. Is it possible to do this in a si

7条回答
  •  自闭症患者
    2020-12-03 18:34

    The simplest explanation is that:

    SELECT IF(1 = 2,'true','false'); --> false
    SELECT IF(1 = 1,' true','false'); --> true
    SELECT IF(1 = 2,' true','false'), IF(1 = 1,' true','false'); --> false | true
    

    The 'if' statement give some functionality to selected values. The structure is something like this:

    SELECT IF(), ...... FROM 
    

    A great explanation can be found here.

提交回复
热议问题