Hi I have a MysQL table in which I save the clients
In one column I save the IP Address,
In other column I set if the client is Active or Not Also I save the name, mail, etc...
If one client left, we just set the Active column to 0, (to keep Payments history and so), when new client arrives we can reassign the same IP
Is there a way to create a UNIQUE constraint to allow just one IP that is ACTIVE ?
example
IP | ACTIVE | DATE
---------------------------------
102 | 1 | 2017-10-12
103 | 1 | 2017-10-12
103 | 0 | 2017-10-13
103 | 0 | 2017-10-09
So It can be multiples rows with the IP and 0 but only one with the IP and 1
I'm thinking about a trigger before INSERT, UPDATE that do a SELECT and verify if there is no other row with that IP and 1 in ACTIVE
Suggestions?