title: MySQL query to Retrieve Main record from main table and Sub records from another table in a single SQL statement
body: <p>I have following Two tables</p>
  <p><strong>Table Name: category</strong></p>
  <pre><code>categoryid         Categoryname
  1                  Mobiles
  2                  Laptops
  </code></pre>
  <p><strong>Table Name: product</strong></p>
  <pre><code>productid          categoryid         productname
  1                  1                  Nokia
  2                  2                  Dell
  3                  1                  Mi
  4                  1                  Samsung
  5                  2                  Lenovo
  </code></pre>
  <p>Now I am looking for single SQL statement which should retrieve everything in a single sql statement.</p>
  <p>Expected output given below:</p>
  <pre><code>recordtype        categoryid     productid           category       productname
  Category          1              0                   Mobiles
  Product           1              1                                  Nokia  
  Product           1              3                                  Mi
  Product           1              4                                  Samsung
  Category          2              0                   Laptops
  Product           2              2                                  Dell
  Product           2              5                                  Lenovo    
  </code></pre>