Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple condition in if statement in my sql trigger
    primarykey
    data
    text
    <p>I am trying to give two condition in IF statement...these below two triggers are not showing any syntax error but they are not working also. </p> <p>trigger :1 :</p> <p>DROP TRIGGER IF EXISTS <code>forumpostTrigger</code> ;</p> <pre><code>CREATE DEFINER = `livecomm`@`localhost` TRIGGER `forumpostTrigger` AFTER INSERT ON `forum_post` FOR EACH ROW BEGIN if( ( SELECT count( * ) FROM forum_post WHERE uid = new.uid AND parent_id IS NOT NULL AND is_answer_accepted ) &gt;=30 ) THEN if( ( SELECT sum( vote_count ) FROM forum_post WHERE uid = new.uid AND parent_id IS NOT NULL AND is_answer_accepted ) &gt;=15 ) THEN INSERT INTO user_badges( uid, bedge_id, is_active ) VALUES ( new.uid, '10', '1' ); DELETE FROM user_badges WHERE uid = new.uid AND badge_id =9; END IF ; END IF ; END </code></pre> <p>Trigger :2:</p> <pre><code>DROP TRIGGER IF EXISTS `forumpostTrigger` ; CREATE DEFINER = `livecomm`@`localhost` TRIGGER `forumpostTrigger` AFTER INSERT ON `forum_post` FOR EACH ROW BEGIN if( ( ( SELECT count( * ) FROM forum_post WHERE uid = new.uid AND parent_id IS NOT NULL AND is_answer_accepted ) &gt;=30 ) &amp;&amp; ( ( SELECT sum( vote_count ) FROM forum_post WHERE uid = new.uid AND parent_id IS NOT NULL AND is_answer_accepted ) &gt;=15 ) ) THEN INSERT INTO user_badges( uid, bedge_id, is_active ) VALUES ( new.uid, '10', '1' ); DELETE FROM user_badges WHERE uid = new.uid AND badge_id =9; END IF ; END </code></pre> <p>How to give multiple conditions for if statement like: <code>if ((condition) &amp;&amp; (condition))</code> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload