Hey

Lets say I have 2 columns in table1

Id Value

Id is obviously primary but I want Value to be unique....

I tried "NOT EXISTS" with a subquery but I cant really seem to get it to work. It would be something like

INSERT INTO table1(value) WHERE VALUES('3');

From then on I dont want 3 to be inserted again in the Value column. I dont care about the ID column.

How do I do this in MySQL?

Thanks for the help

Recommended Answers

All 2 Replies

Create the table with a UNIQUE index on the Value field.

Smeagle13 is correct but also change your insert so it will ignore the error generated when the duplicate insert is refused:

INSERT IGNORE INTO TABLE1 WHERE VALUES('3');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.