title: MySQL - Select multiple rows from different table in one query
body: <p>I have 2 tables &quot;products&quot; and &quot;products_images&quot;., I want to load each product with it's images in the same query and then json_encode then send it to front end.</p>
  <pre><code>products table
  +----+----------------+-------+
  | id | product_name   | price |
  +----+----------------+-------+
  | 1  | product name 1 | 15    |
  +----+----------------+-------+
  | 2  | product name 2 | 23.25 |
  +----+----------------+-------+
  | 3  | product name 3 | 50    |
  +----+----------------+-------+
  
  
  product_images table
  +----+------------+-----------------------------------------------------+
  | id | product_id | image                                               |
  +----+------------+-----------------------------------------------------+
  | 1  | 1          | e5j7eof75y6ey6ke97et5g9thec7e5fnhv54eg9t6gh65bf.png |
  +----+------------+-----------------------------------------------------+
  | 2  | 1          | sefuywe75wjmce5y98nvb7v939ty89e5h45mg5879dghkjh.png |
  +----+------------+-----------------------------------------------------+
  | 3  | 1          | 7u5f9e6jumw75f69w6jc89fwmykdy0tw78if6575m7489tf.png |
  +----+------------+-----------------------------------------------------+
  </code></pre>
  <p>I want the query to return this</p>
  <pre><code>{
    id: 5,
    product_name: 'product name 1',
    price: 25.23,
    images: [
     {
      id: 1,
      image: 'e5j7eof75y6ey6ke97et5g9thec7e5fnhv54eg9t6gh65bf.png'
     },
     {
      id: 2,
      image: 'sefuywe75wjmce5y98nvb7v939ty89e5h45mg5879dghkjh.png'
     },
    ]
  }
  </code></pre>
  <p>What I do is I make a loop on each product in php and then load it's images, but I don't believe this is the best solution or the best performance.</p>