Usage of MySQL's “IF EXISTS”

前端 未结 5 1978
Happy的楠姐
Happy的楠姐 2020-11-22 13:25

Here are two statements that I\'d like to work, but which return error messages:

IF EXISTS (SELECT * FROM gdata_calendars WHERE `group` =  ? AND id = ?) SELE         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 13:45

    if exists(select * from db1.table1 where sno=1 )
    begin
    select * from db1.table1 where sno=1 
    end
    else if (select * from db2.table1 where sno=1 )
    begin
    select * from db2.table1 where sno=1 
    end
    else
    begin
    print 'the record does not exits'
    end
    

提交回复
热议问题