title: Mysql - Add row as column
body: <p>I am having a table called <code>listings</code>. A listing can have 2 images, a front and a back-image.</p>
  <p>I currently join the tables and get the following output:</p>
  <pre><code>**Schema (MySQL v5.7)**
  
      CREATE TABLE `images` (
        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
        `listings_id` int(11) DEFAULT NULL,
        `file_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
        `properties` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
        `created_at` timestamp NULL DEFAULT NULL,
        `updated_at` timestamp NULL DEFAULT NULL,
        PRIMARY KEY (`id`)
      );
      
      CREATE TABLE `listings` (
        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
        `title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
        `price` double(8,2) NOT NULL,
        `created_at` timestamp NULL DEFAULT NULL,
        `updated_at` timestamp NULL DEFAULT NULL,
        PRIMARY KEY (`id`)
      );
      
      INSERT INTO images (id, listings_id, file_name, properties, created_at, updated_at) VALUES(1, 1, 'trv_front.png', '[{&quot;front_back&quot;:&quot;front&quot;,&quot;path&quot;:null}]', '2021-10-16 07:08:06', '2021-10-16 07:08:06');
      INSERT INTO images (id, listings_id, file_name, properties, created_at, updated_at) VALUES(2, 2, '20211016070806_trv.png', '[{&quot;front_back&quot;:&quot;front&quot;,&quot;path&quot;:null}]', '2021-10-16 07:08:06', '2021-10-16 07:08:06');
      INSERT INTO images (id, listings_id, file_name, properties, created_at, updated_at) VALUES(3, 1, '2_rv.png', '[{&quot;front_back&quot;:&quot;back&quot;,&quot;path&quot;:null}]','2021-10-16 07:08:06', '2021-10-16 07:08:06');
      INSERT INTO images (id, listings_id, file_name, properties, created_at, updated_at) VALUES(4, 2, 'backd.png', '[{&quot;front_back&quot;:&quot;back&quot;,&quot;path&quot;:null}]','2021-10-16 07:08:06', '2021-10-16 07:08:06');
      
      INSERT INTO listings (id, title, price, created_at, updated_at) VALUES(1, 'test1', 10, '2021-10-16 08:14:08', '2021-10-16 08:14:08');
      INSERT INTO listings (id, title, price, created_at, updated_at) VALUES(2, 'test2', 42, '2021-10-16 08:14:08', '2021-10-16 08:14:08');
      INSERT INTO listings (id, title, price, created_at, updated_at) VALUES(3, 'test3', 43, '2021-10-16 08:14:08', '2021-10-16 08:14:08');
      INSERT INTO listings (id, title, price, created_at, updated_at) VALUES(4, 'test4', 50, '2021-10-16 08:14:08', '2021-10-16 08:14:08');
  
  ---
  
  **Query #1**
  
      select l.id, l.title, i.file_name, i.listings_id, i.properties from listings l
      left join images i on i.listings_id = l.id order by l.id;
  
  | id  | title | file_name              | listings_id | properties                           |
  | --- | ----- | ---------------------- | ----------- | ------------------------------------ |
  | 1   | test1 | trv_front.png          | 1           | [{&quot;front_back&quot;:&quot;front&quot;,&quot;path&quot;:null}] |
  | 1   | test1 | 2_rv.png               | 1           | [{&quot;front_back&quot;:&quot;back&quot;,&quot;path&quot;:null}]  |
  | 2   | test2 | 20211016070806_trv.png | 2           | [{&quot;front_back&quot;:&quot;front&quot;,&quot;path&quot;:null}] |
  | 2   | test2 | backd.png              | 2           | [{&quot;front_back&quot;:&quot;back&quot;,&quot;path&quot;:null}]  |
  | 3   | test3 |                        |             |                                      |
  | 4   | test4 |                        |             |                                      |
  
  </code></pre>
  <p>As you can see in the properties-column there I can see if the image is front or the back side.</p>
  <p>However, I would like to get the following structure adding the two columns <code>front_image</code> and <code>back_image</code>:</p>
  <pre><code>| id | title | file_name              | listings_id | front_image             | back_image |
  |----|-------|------------------------|-------------|-------------------------|------------|
  | 1  | test1 | trv_front.png          | 1           | trv_front.png           | 2_rv.png   |
  | 2  | test2 | 20211016070806_trv.png | 2           | 220211016070806_trv.png | backd.png  |
  | 3  | test3 |                        |             |                         |            |
  | 4  | test4 |                        |             |                         |            |
  </code></pre>
  <p><a href="https://www.db-fiddle.com/f/qC4ki1YS8aitrzXSBy9CCF/1" rel="nofollow noreferrer">This is my dbfiddle</a>.</p>
  <p>Any suggestions how to add the image columns?</p>
  <p>I appreciate your replies!</p>