0

I am trying to create an event and its Do part I am inserting one row but before inserting it ... for its one column i am trying getting value from a select query and then trying to add that in insert query . can some one tell me ... what is wrong with the query.

CREATE EVENT test_event_04 ON SCHEDULE EVERY 1 MINUTE STARTS CURRENT_TIMESTAMP DO 
INSERT INTO Exam_Triger(Questions,CAT_ID,TOPIC_ID,SCHEDULED_TYPE,UPDATE_USER,UPDATE_DT,CREATE_USER,CREATE_DT) 
VALUES(id, 2,2,'Weekly','',curdate(),'',curdate())
select id 
from ( 
    select  GROUP_CONCAT(id SEPARATOR ',')as id 
    from (
        select id 
        from question_data 
        order by rand() 
        limit 4
    )as ls
) as ps
Barmar
  • 741,623
  • 53
  • 500
  • 612
sonu
  • 1
  • 3
  • 1
    You can't use both `VALUES` and `SELECT` as the source of data in `INSERT`. – Barmar Apr 08 '21 at 20:07
  • The event part is irrelevant. You would get the same syntax error if you tried to do this outside of an event. – Barmar Apr 08 '21 at 20:12
  • Remove `VALUES` clause at all but use `SELECT id, 2,2,'Weekly','',curdate(),'',curdate()`.. from the other side - what is the reason for to insert new line each minute? – Akina Apr 08 '21 at 20:14
  • this one min .. i have just added for testing. – sonu Apr 09 '21 at 03:20
  • i need to fetch ids with comma separated from one table and that i need to insert in my trigger table column – sonu Apr 09 '21 at 03:22
  • 0 My issue has been resolved, Below is the query which is working for me INSERT INTO Exam_Trigger(Questions,CAT_ID,TOPIC_ID,SCHEDULED_TYPE,UPDATE_USER,UPDATE_DT,CREATE_USER,CREATE_DT) select id ,'2','2','Weekly','',curdate(),'',curdate() from ( select GROUP_CONCAT(id SEPARATOR ',')as id from(select id from question_data order by rand() limit 4)as ls) as ps – sonu Apr 09 '21 at 03:34

0 Answers0