• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prevent duplicate record

#1
Hi
I have a like table that have user_id and comment_id field
I need user only can like once each comment and i dont want to check it with SELECT
Maybe adjust table column that occur error when insert record?
Like primary error
I attach my table shot
I want only insert record example
user_id,comment_id
2,4

for next insert,show error for insert
Maybe?
Reply

#2
There is no way to check it without using a select.

Code:
SELECT EXISTS(SELECT * FROM yourTableName WHERE yourCondition);

I would make sure that both columns are index.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(06-10-2020, 03:07 AM)InsiteFX Wrote: There is no way to check it without using a select.

Code:
SELECT EXISTS(SELECT * FROM yourTableName WHERE yourCondition);

I would make sure that both columns are index.
Thanks but
I remember we could implement this feature with add key on fields and prevent duplicate records
But i dont know how do it
Reply

#4
Not sure but this might be what your looking for.

MySQL - Handling Duplicates
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(06-10-2020, 07:59 AM)InsiteFX Wrote: Not sure but this might be what your looking for.

MySQL - Handling Duplicates

Thank you

(06-10-2020, 07:59 AM)InsiteFX Wrote: Not sure but this might be what your looking for.

MySQL - Handling Duplicates
It's working good very thanks
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.