Allowed duplicate data MySQL
<p>I'm using a internet application which is named Dolibarr and I would like to modify a MySQL condition in the <code>llx_cotisation</code> table.</p>

<p>This table doesn't allow the same cotisation date per member. For example, I can't have a member which paid 2 different cotisations the same day. Because the field <code>dateadh</code>can't be the same for a member. If I try to add an other cotisation with the same date to the first one, I get an MySQL error :</p>

<pre><code>Duplicate entry '3-2016-01-01 00:00:00' for key 'uk_cotisation'
</code></pre>

<p>This is the table structure :</p>

<pre><code>mysql&gt; describe llx_cotisation ;
+-------------+-----------+------+-----+-------------------+-----------------------------+
| Field       | Type      | Null | Key | Default           | Extra                       |
+-------------+-----------+------+-----+-------------------+-----------------------------+
| rowid       | int(11)   | NO   | PRI | NULL              | auto_increment              |
| tms         | timestamp | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| datec       | datetime  | YES  |     | NULL              |                             |
| fk_adherent | int(11)   | YES  | MUL | NULL              |                             |
| dateadh     | datetime  | YES  |     | NULL              |                             |
| datef       | date      | YES  |     | NULL              |                             |
| cotisation  | double    | YES  |     | NULL              |                             |
| fk_bank     | int(11)   | YES  |     | NULL              |                             |
| note        | text      | YES  |     | NULL              |                             |
+-------------+-----------+------+-----+-------------------+-----------------------------+
9 rows in set (0.00 sec)
</code></pre>

<p>The field is : <code>dateadh</code></p>

<p>Is it possible to allow duplicating value there ?</p>

<p>The part of script in php looks like :</p>

<pre><code>   // List of subscriptions
    $sql = "
    SELECT d.rowid
         , d.login
         , d.firstname
         , d.lastname
         , d.societe
         , c.rowid as crowid
         , c.cotisation
         , c.dateadh
         , c.datef
         , c.fk_bank as bank
         , c.note
         , b.fk_account
      FROM ".MAIN_DB_PREFIX."adherent as d
         , ".MAIN_DB_PREFIX."cotisation as c
      LEFT 
      JOIN ".MAIN_DB_PREFIX."bank as b 
        ON c.fk_bank=b.rowid
     WHERE d.rowid = c.fk_adherent
     ";
    if (isset($date_select) &amp;&amp; $date_select != '')
    {
        $sql.= " AND c.dateadh LIKE '".$date_select."%'";
    }
    if ($search_ref)
    {
            if (is_numeric($search_ref)) $sql.= " AND (c.rowid = ".$db-&gt;escape($search_ref).")";
            else $sql.=" AND 1 = 2";    // Always wrong
    }
</code></pre>

<p>Thank you so much if you could help me, and I sorry for my very bad English :/</p>

<p>EDIT : this is the result to the command : <code>show create table llx_cotisation</code></p>

<pre><code>| llx_cotisation | CREATE TABLE `llx_cotisation` (
  `rowid` int(11) NOT NULL AUTO_INCREMENT,
  `tms` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `datec` datetime DEFAULT NULL,
  `fk_adherent` int(11) DEFAULT NULL,
  `dateadh` datetime DEFAULT NULL,
  `datef` date DEFAULT NULL,
  `cotisation` double DEFAULT NULL,
  `fk_bank` int(11) DEFAULT NULL,
  `note` text,
  PRIMARY KEY (`rowid`),
  UNIQUE KEY `uk_cotisation` (`fk_adherent`,`dateadh`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 |
</code></pre>

<p><strong>SOLUTION :</strong></p>

<p>I removed the UNIQUE KEY and it seems to work perfectly !</p>