title: Using Nested SQL Sub-queries in SQL Injection
body: <p>This question just came into my mind and wasn't able to find this anywhere so thought this would be the best place to ask. This is just for education purpose. I use proper sanitation and haven't provided DROP permission for my real database.</p>
  
  <p>Let's assume a database with all permissions and a simple insert query with three values</p>
  
  <pre><code>INSERT INTO test(a,b,c) VALUES('$a','$b','$c');
  </code></pre>
  
  <p>The above query is vulnerable to sql injection.</p>
  
  <p>Let's assume the user input to be</p>
  
  <ul>
  <li>a',(select DATABASE()),'a')-- </li>
  <li>begone2</li>
  <li>begone3</li>
  </ul>
  
  <p>The resulting query would be this:</p>
  
  <pre><code>INSERT INTO test(a,b,c) VALUES('a',(select DATABASE()),'a')-- ','begone2','begone3')
  </code></pre>
  
  <p>This above query would execute and insert the database name into the table but my question is <em>Will a attacker will able to drop the database without actually knowing the database name?</em>, with a query like this:</p>
  
  <pre><code>INSERT INTO test(a,b,c) VALUES
  ('a',(DROP DATABASE (select DATABASE())),'a')-- ','begone2','begone3')
  </code></pre>
  
  <p>I tried running the above query and it throws a error. What's wrong with this query?</p>