title: MySQL Insert from 2 source tables to one destination table
body: <p>I am having issues inserting Id fields from two tables into a single record in a third table.  </p>
  
  <pre><code>mysql&gt; describe ing_titles;
  +----------+------------------+------+-----+---------+----------------+
  | Field    | Type             | Null | Key | Default | Extra          |
  +----------+------------------+------+-----+---------+----------------+
  | ID_Title | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
  | title    | varchar(64)      | NO   | UNI | NULL    |                |
  +----------+------------------+------+-----+---------+----------------+
  2 rows in set (0.22 sec)
  
  mysql&gt; describe ing_categories;
  +-------------+------------------+------+-----+---------+----------------+
  | Field       | Type             | Null | Key | Default | Extra          |
  +-------------+------------------+------+-----+---------+----------------+
  | ID_Category | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
  | category    | varchar(64)      | NO   | UNI | NULL    |                |
  +-------------+------------------+------+-----+---------+----------------+
  2 rows in set (0.02 sec)
  
  mysql&gt; describe ing_title_categories;
  +-------------------+------------------+------+-----+---------+----------------+
  | Field             | Type             | Null | Key | Default | Extra          |
  +-------------------+------------------+------+-----+---------+----------------+
  | ID_Title_Category | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
  | ID_Title          | int(10) unsigned | NO   | MUL | NULL    |                |
  | ID_Category       | int(10) unsigned | NO   | MUL | NULL    |                |
  +-------------------+------------------+------+-----+---------+----------------+
  3 rows in set (0.04 sec)   
  </code></pre>
  
  <p>Let's say the data from the tables is:  </p>
  
  <pre><code>mysql&gt; select * from ing_titles;
  +----------+-------------------+
  | ID_Title | title             |
  +----------+-------------------+
  |        3 | Chicken           |
  |        2 | corn              |
  |        1 | Fettucini Alfredo |
  +----------+-------------------+
  3 rows in set (0.00 sec)
  
  mysql&gt; select * from ing_categories;
  +-------------+----------+
  | ID_Category | category |
  +-------------+----------+
  |           1 | Dinner   |
  |           3 | Meat     |
  |           2 | Veggie   |
  +-------------+----------+
  3 rows in set (0.00 sec)  
  </code></pre>
  
  <p>I want to insert into <code>ing_title_categories</code> the record "corn, Veggie" or where ID_Title = 2 and ID_Category = 2.</p>
  
  <p>Here's what I tried:  </p>
  
  <pre><code>INSERT INTO ing_title_categories (ID_Title, ID_Category)
  SELECT ing_titles.ID_Title, ing_categories.ID_Category
  FROM ing_title_categories
      LEFT JOIN ing_titles ON ing_title_categories.ID_Title=ing_titles.ID_Title
      LEFT JOIN ing_categories ON ing_title_categories.ID_Category=ing_categories.ID_Category
  WHERE (ing_titles.ID_Title=2) AND (ing_categories.ID_Category = 2);
  </code></pre>
  
  <p>There is no data inserted into the table <code>ing_title_categories</code>, and here is the reply from MySQL:  </p>
  
  <pre><code>Query OK, 0 rows affected (0.00 sec)
  Records: 0  Duplicates: 0  Warnings: 0
  </code></pre>
  
  <p>What is the correct syntax for inserting the <code>ing_titles.ID_Title</code> and <code>ing_categories.ID_Category</code> into the table <code>ing_titles_categories</code>?</p>
  
  <p><em>Please, no PHP or Python examples.  Use SQL that I can copy and paste into the MySQL prompt.  I will be adding this to a C++ program, not PHP, JavaScript or Python.</em></p>
  
  <p><strong>Edit 1:</strong> 
  The <code>ing_title_categories.ID_Title</code> and <code>ing_title_categories.ID_Category</code> are foreign keys into the other tables.  </p>