title: How to insert into table with values from another tables - mysql inner join
body: <p>In this case i have created 2 tables:</p>
  <p>Projects:</p>
  <pre><code>CREATE TABLE projects (
  ID int(5) NOT NULL,
  PROJECT_NAME varchar(50) NOT NULL
  );
  </code></pre>
  <p>Modules:</p>
  <pre><code>CREATE TABLE modules (
  ID_MODULE int(11) NOT NULL,
  NAME varchar(50),
  ID_PROJECT int(11) DEFAULT NULL
  );
  </code></pre>
  <p>I've inserted data to projects table:</p>
  <pre><code>INSERT INTO projects (ID, PROJECT_NAME) VALUES
  (1, 'BOX'),
  (2, 'Duck')
  </code></pre>
  <p>Now I'd like to insert data into &quot;modules&quot; table, but not with ID_PROJECT. I want insert with PROJECT_NAME from &quot;projects&quot; table. When i tried with bellow command:</p>
  <pre><code>INSERT INTO modules (ID_MODULE, NAME, projects.PROJECT_NAME)
  SELECT 1, 'S-BOX', projects.PROJECT_NAME
  FROM modules INNER JOIN projects
  ON modules.ID_PROJECT = projects.ID AND projects.PROJECT_NAME = 'BOX';
  </code></pre>
  <p>It shew an error:</p>
  <h1>1054 - Unknown column 'projects.PROJECT_NAME' in  field list</h1>
  <p>But when i wrote like this:</p>
  <pre><code>INSERT INTO modules (ID_MODULE, NAME, ID_PROJECT)
  SELECT 1, 'S-BOX', projects.PROJECT_NAME
  FROM modules INNER JOIN projects
  ON modules.ID_PROJECT = projects.ID AND projects.PROJECT_NAME = 'BOX';
  </code></pre>
  <p>It didn't show any error, but it didn't insert any row record to &quot;modules&quot; table.</p>
  <p>I have a question is it possible to insert into &quot;modules&quot; table values with inner join another table (inner join &quot;projects&quot; table)? If yes tell what should i do. Thx for any help.</p>
  <p><strong>For example:</strong></p>
  <p>In &quot;modules&quot; table i haven't insert anything. But want insert data:</p>
  <pre><code>ID_MODULE = 1
  NAME = &quot;S-BOX&quot;
  projects.PROJECT_NAME = &quot;BOX&quot; (which is inner joined on modules.ID_PROJECT = projects.ID)
  </code></pre>