title: Selecting multiple rows based on specific categories (mysql)
body: <p>I don't think this is a duplicate posting because I've looked around and this seems a bit more specific than whats already been asked (but I could be wrong).</p>
  
  <p>I have 4 tables and one of them is just a lookup table</p>
  
  <pre><code>SELECT exercises.id as exid, name, sets, reps, type, movement, categories.id
  FROM exercises
  INNER JOIN exercisecategory ON exercises.id = exerciseid
  INNER JOIN categories ON categoryid = categories.id
  INNER JOIN workoutcategory ON workoutid = workoutcategory.id
  WHERE (workoutcategory.id = '$workouttypeid')
  AND rand_id &gt; UNIX_TIMESTAMP() 
  ORDER BY rand_id ASC LIMIT 6;
  </code></pre>
  
  <p><em>exercises</em> table contains a list of exercise names, sets, reps, and an id</p>
  
  <p><em>categories</em> table contains an id, musclegroup, and type of movement</p>
  
  <p><em>workoutcategory</em> table contains an id, and a more specific motion (ie: upper body push, or upper body pull)</p>
  
  <p><em>exercisecategory</em> table is the lookup table that contains (and matches the id's) for exerciseid, categoryid, and workoutid</p>
  
  <p>I've also added a column to the exercises table that generates a random number upon entering the row in the database. This number is then updated only for the specified category when it is called, and then sorted and displays the ascending order of the top 6 listings. This generates a nice random entry for me. (Found that solution elsewhere here on SO).</p>
  
  <p>This works fine for generating 6 random exercises from a specific top level category. But I'd like to drill down further. Here's an example...</p>
  
  <p>select all rows inside categoryid 4</p>
  
  <p>then still within the category 4 results, find all that have movementid 2, and then find one entry with a typeid 1, then another for typeid 2, etc</p>
  
  <p><strong>TLDR;</strong> Basically there's a few levels of categories and I'm looking to select a few from here and a few from there and they're all within this top level. I'm thinking this could all be executed within more than one query but im not sure how... in the end I'm looking to end with one array of the randomized entries.</p>
  
  <p>Sorry for the long read, its the best explanation I've got.</p>