I am faced with the challenge of avoiding duplicate entries in a table that contains ID, title, and userid fields. Currently, I have implemented logic to store view history in the database when certain media is viewed.
However, despite my efforts, duplicate entries are still occurring even after trying the following code:
dataAccessor.viewers = {
add: ({ courseId, viewerOid }) => {
const query =
"IF NOT EXISTS (SELECT * FROM course_video_viewers WHERE course_id = ? AND WHERE azure_oid = ?) INSERT INTO course_video_viewers (course_id, azure_oid) VALUES (?, ?)";
const inputs = [courseId, viewerOid];
return sendQueryAndReturnResultsAsPromise(query, inputs);
}
};