Don't know if this is possible for MySQL because I know that it doesn't support check constraints, but what I want is to make two columns unique. Before you answer with
ALTER TABLE <table_name> ADD UNIQUE(<col1>, <col2>);
I think you should try to reorganize your database. Let's say currently you have this:
Table: users
id name email new_email
102 foo foo@mail.com foo2@mail.com
103 bar bar@mail.com bar2@mail.com
104 baz baz@mail.com NULL
This could be changed to:
Table: users
id name
102 foo
103 bar
104 baz
Table: emails
user_id is_new email
102 0 foo@mail.com
102 1 foo2@mail.com
103 0 bar@mail.com
103 1 bar2@mail.com
104 0 baz@mail.com
You can then add a unique index on the final table on the column email
.