title: How do I specify a timespan as a key in an unique constraint for multiple columns in MySQL?
body: <p>I have a table where I add thousands of rows each time I update. Each row describes the current value of a single item. </p>
  
  <p>I want to add a constraint that only allows 1 insert for a certain ItemID for a certain timespan, for example an hour.</p>
  
  <p>In other words I would like one column in my table the <em>"itemID"</em> and a <em>"timespan"</em> be a unique constraint for my table.</p>
  
  <p>So I thought I would somehow add something like this:</p>
  
  <pre><code>BETWEEN DATE_ADD(NOW(),INTERVAL -1 HOUR) AND NOW() AS timespan
  </code></pre>
  
  <p>When I alter my table <em>(the "itemID" is irrelevant, just a column in my table")</em></p>
  
  <pre><code>ALTER TABLE `items_update` ADD UNIQUE `unique_timespan`(`itemID`, `timespan`);
  </code></pre>
  
  <p>Can it be done? Or do I have to make a nested INSERT query that checks for this?</p>