I'm currently building a site that requires information to be submitted by the users but must remain unique in some aspect in the mySQL database (no duplicate emails, etc.).

However, I'm kinda confused on how the UNIQUE constraint will actually play out with the database if I use it and I was hoping someone would be willing to explain the in's and out's a bit.

I understand that UNIQUE ensures that duplicate data is not stored but what if I had a column in the database say, "city" set as unique and two users from two different cities with the same name (eg. Hamilton, Ohio and Hamilton, NZ) submit information? Will one user not be accepted because the word "Hamilton" already existed? And if they were to be accepted, how does the database associate the two for proper data retrieval?

Because of the nature of the site, this will definitely have to be a many-to-many relationship but I just can't seem to grasp the workings of it in my head if columns are set as UNIQUE.

Thanks for the help.