Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to prevent duplicate entries but allow duplicates in one column MYSQL?

I have a MYSQL table that stores restaurant IDs to email address. Any given email address can have as many restaurant IDs added to it. for example:

| email VARCHAR(45) | restaurant-id VARCHAR(45) |

fakeemail@gmail.com | 12534134134135341
fakeemail@gmail.com | 44341341341341343
fakeemail@gmail.com | 65656542242434134
supercool@gmail.com | 12534134134135341
totallyreal@gma.com | 44341341341341343
lolzzz123@gmail.com | 65656542242434134

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I currently have no primary key set because both columns need to be able to have duplicate entires. What I am looking to prevent is the following duplicates:

fakeemail@gmail.com | 12534134134135341
fakeemail@gmail.com | 12534134134135341
fakeemail@gmail.com | 12534134134135341

^^ How can i prevent the above while still allowing both columns to have duplicates?

>Solution :

SELECT 
email,
restaurant-id
FROM 
your_table
GROUP BY 
email,
restaurant-id
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading