mysql - insert record if not exists in sql, duplicate column name -
I wanted a solution to insert a record, if it was not there, then I searched here and found a solution but I have Second problem
Include in closed goals (Question_ID, subject_id) SELECT * from (SELECT 2, 2) where TMP exists (select the question from the close_resources WHERE Question_id = 2 and subject_id = 2) LIMIT 1
Output is
# 1060 - Duplicate column name '2'
If I If I use any 2 numbers I am not equal, this will work but the problem arises when it is 2 characters.
The smallest change is to add nicknames in your selection statement to your SQL work:
Insert in closed buttons (Question_ID, subject_id) SELECT * FROM ( SELECT 2 AS question_id, 2 AS subject_id) where AS TMP is not present (Select Question_ID closed_sessions from WHER E Question_ID = 2 and topic_id = 2) LIMIT 1
However if you have a unique barrier at (question_id, subject_id)
, you can change the INSERT IGNORE
:
Sign in closed buttons (Question_ID, subject_id) value (2, 2)
< / Div>
Comments
Post a Comment