how to use if not exists while inserting a row mysql

后端 未结 3 2056
我寻月下人不归
我寻月下人不归 2021-01-24 08:17

The thing that i want to do is to check if there is a same row and if not to insert a new row to the table.

In that case, how can i use if not exists ?

3条回答
  •  余生分开走
    2021-01-24 08:58

    INSERT INTO `facebook` (`ID`,`fb_id`,`label_id`,`page_ids`,`token`) 
    SELECT NULL, '". $session['id'] ."', '$id', '', '". $access_token ."'
    FROM DUAL
    WHERE NOT EXISTS (SELECT 'x' FROM facebook WHERE label_id = '$id')
    

    I think FROM DUAL is optional, but I'm an Oracle guy. :)

提交回复
热议问题