title: MySQL: SELECT value WHERE subquery returns a wildcarded value
body: <p>Confusing title...my apologies.  </p>
  
  <p>What I've got is a table with two related rows.  I need to get the value of a column in one row based on the value of a column in another row.</p>
  
  <p>Given the following postmeta table: </p>
  
  <pre><code>+----------+------------+---------------------------------------------------+--------------------+
  | meta_id  | post_id    | meta_key                                          |  meta_value        |
  +----------+------------+---------------------------------------------------+--------------------+
  | 6917     | 661        | member_categories_0_member_categories_name        | 11                 |
  +----------+------------+---------------------------------------------------+--------------------+
  | 6918     | 661        | member_categories_0_member_categories_description | First description  |
  +----------+------------+---------------------------------------------------+--------------------+
  | 6919     | 661        | member_categories_1_member_categories_name        | 12                 |
  +----------+------------+---------------------------------------------------+--------------------+
  | 6920     | 661        | member_categories_1_member_categories_description | Second description |
  +----------+------------+---------------------------------------------------+--------------------+
  </code></pre>
  
  <p>I need to get the meta_value category description based on the meta_value category ID and the post_id.  For instance, if my category ID is 11 and my post_id is 661, I should get "First description".</p>
  
  <p>I thought about using a subquery to get the meta_key corresponding with a meta_value of '11', but I don't know how to find the description based on the counter inside 'member_categories_x_member_categories_name'.  </p>
  
  <p>Unfortunately, I don't have control over the name of the meta_key.  I got as far as this simple query, which returns 'member_categories_0_member_categories_name'.  How do I use that value to find 'First description'?</p>
  
  <pre><code>    SELECT pm.meta_key 
      FROM postmeta pm
      WHERE pm.meta_value = "11"
      AND pm.post_id = 661
  </code></pre>
  
  <p>Here's the SQL for the table:</p>
  
  <pre><code>CREATE TABLE `postmeta` (
      `meta_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
      `post_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
      `meta_key` VARCHAR(255) NULL DEFAULT NULL,
      `meta_value` LONGTEXT NULL,
      PRIMARY KEY (`meta_id`),
      INDEX `post_id` (`post_id`),
      INDEX `meta_key` (`meta_key`)
  )
  COLLATE='utf8_general_ci'
  ENGINE=InnoDB
  AUTO_INCREMENT=30814;
  
  INSERT INTO `postmeta` (`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (6917, 661, 'member_categories_0_member_categories_name', '11');
  INSERT INTO `postmeta` (`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (6918, 661, 'member_categories_0_member_categories_description', 'First description');
  INSERT INTO `postmeta` (`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (6919, 661, 'member_categories_1_member_categories_name', '12');
  INSERT INTO `postmeta` (`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (6920, 661, 'member_categories_1_member_categories_description', 'Second description');
  </code></pre>