How can I count the view value in mysql table. If the first user like the post in the viewdetails table insert a row with Counts column value 1, If the next user like the post just update the Counts column(previous Counts value +1) ,without check anything.
So I tried and take a sytax from internet Duplicate Key, but I don't know how to used it.
I tried below
INSERT INTO viewdetails
(PostID,Counts)
VALUES
(1, 1)
ON DUPLICATE KEY UPDATE
Counts = VALUES(Counts)+1
The above example is working like below
1st execution
Insert Counts => 2
2nd execution Update Counts => 2
3rd execution Update Counts => 2
But I need like below
1st execution
Insert Counts => 1
2nd execution Update Counts => 1+1
3rd execution Update Counts => 2+1