How to INSERT
a row in a table if this row doesn't already exist in same table?
I want something like this.
insert into note (note_id, user_book_id, course_user_id, book_edition_id, book_id, role_type_id, page_id, book_page_number, xcoord, ycoord,
width, height, share_across_courses, date_created, date_updated, created_by, updated_by, description, share_with_students,text)
select note_s.nextval, i_user_book_id, i_course_user_id, book_edition_id, book_id, n.role_type_id, page_id, book_page_number, xcoord, ycoord, width, height, share_across_courses, sysdate, sysdate, i_user_id, i_user_id, description, share_with_students,text
from note n inner join course_user cu
on n.course_user_id = cu.course_user_id
where cu.course_id = 23846
and where not exists (select note_s.nextval, i_user_book_id, i_course_user_id, book_edition_id, book_id, n.role_type_id, page_id, book_page_number, xcoord, ycoord,
width, height, share_across_courses, sysdate, sysdate, i_user_id, i_user_id, description, share_with_students,text
from note n inner join course_user cu
on n.course_user_id = cu.course_user_id
where cu.course_id = 23846);
That is, in note table if record is already present for a particular course_user_id then do nothing. Otherwise if no entry for that particular course_user_id then insert into note for that course_user_id.
But my code is not working.
Here, note_id
is PRIMARY KEY
in note table and Course_user_id
is PRIMARY KEY
in course_user table.