Not allowing duplicate records

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Wardy7
Forum Commoner
Posts: 38
Joined: Wed Aug 24, 2005 4:45 am
Location: UK

Not allowing duplicate records

Post by Wardy7 »

I have a database that has the following userid, frienduserid, friendusername in it.

What happens is that a user (userid) can add anotehr user as their friend.
So this means any user can add any other user to their friends list.
When a user clicks on the "add friend" link on my site the details are updated with the "new friend partnership". What I am havign problems with is that a user can add the samne friend as many times as they want, so what I need is that if a user alreday has a friendship then if they try to add another then it doesn't get added.

Can anyone help please?

Cheers
Wardy
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

friendusername technically isn't needed for this table.

As for the proper query to see if an entry already exists, it would be a JOIN between the user table and frienduserid. You've already got the right userid and will need that too, but no join is required for that field.
Post Reply