title: Using SQL Sub-queries in an INSERT Statement
body: <p>Here are the two tables created:</p>
  
  <pre><code>CREATE TABLE category_tbl(
  id int NOT NULL AUTO_INCREMENT,
  name varchar(255) NOT NULL,
  subcategory varchar(255) NOT NULL,
  PRIMARY KEY(id),
  CONSTRAINT nameSubcategory UNIQUE KEY(name, subcategory)
  ) ENGINE=InnoDB;
  
  CREATE TABLE device(
  id INT NOT NULL AUTO_INCREMENT,
  cid INT DEFAULT NULL,
  name VARCHAR(255) NOT NULL,
  received DATE,
  isbroken BOOLEAN,
  PRIMARY KEY(id),
  FOREIGN KEY(cid) REFERENCES category_tbl(id)
  ) ENGINE=InnoDB;
  </code></pre>
  
  <p>Below is the instruction that was given to me:</p>
  
  <pre><code>-- insert the following devices instances into the device table (you should use a subquery to set up foriegn keys referecnes, no hard coded numbers):
  -- cid - reference to name: phone subcategory: maybe a tablet?
  -- name - Samsung Atlas
  -- received - 1/2/1970
  -- isbroken - True
  </code></pre>
  
  <p>I'm getting errors on the insert statement below from attempting to use a sub-query within an insert statement. How would you solve this issue?</p>
  
  <pre><code>INSERT INTO devices(cid, name, received, isbroken)
  VALUES((SELECT id FROM category_tbl WHERE subcategory = 'tablet')  , 'Samsung Atlas', 1/2/1970, 'True');
  </code></pre>