troubleshooting Question

Insert multiple rows and columns into MySQL while ignoring duplicates in one column

Avatar of solrac149
solrac149 asked on
11 Comments1 Solution618 ViewsLast Modified:
I want to insert rows into MySQL for three columns, but ignore the insert if ALL THREE COLUMNS are duplicates

Here's my current sql statement in PHP (example):

$sql = "INSERT INTO test
(id_number, user_id, username)

This works fine, however if there was already an id_number of '1234' in the database, it will now have two such entries.

I would like 1234 to be ignored, but ONLY if:
1234 is already present in a row
user id 10 is already present in same row
username john is already present in same row

Is this possible in one SQL statement?

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros