title: Single MySQL field with comma separated values
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3971622/mysql-is-array-in-multiple-columns">mysql is array in multiple columns</a>  </p>
  </blockquote>
  
  
  
  <p>I have two tables:</p>
  
  <p>Posts Table</p>
  
  <pre><code>PostID | Gallery
    1    | 4,7,8,12,13
    2    | 1,2,3,4
    3    | 5,8,9
    4    | 3,6,11,14
  </code></pre>
  
  <p>The values in Gallery are the primary keys in the Images table:</p>
  
  <p>Images Table</p>
  
  <pre><code>ImageID | FileName
     1    | something.jpg
     2    | lorem.jpg
     3    | ipsum.jpg
     4    | what.jpg
     5    | why.jpg
  </code></pre>
  
  <p>The reason I do this instead of just adding a PostID key to the Images table is because those images can be associated with a lot of different posts. I suppose I could add another table for the relationships, but the comma-separated value is easier to work with as far as the jQuery script I am using to add to it.</p>
  
  <p>If I'm on a page that requires the images associated with PostID 3, what kind of query can I run to output all of the FileNames for it?</p>