mysqlsqlselectformattabular

How to align a column right-adjusted


I want to align a column in my table. In this case 'Title'

mysql> SELECT Titel, KuenstlerName from Bild;
+--------------------------+---------------+
| Title                    |         Artist|
+--------------------------+---------------+
| Drei Musikanten          | Picasso       |
| Buveuse assoupie         | Picasso       |
| Die Flöte des Pan        | Picasso       |
| Paolo als Harlekin       | Picasso       |
| Die Umarmung             | Picasso       |
| Sitzende Frau            | Picasso       |
| Sternennacht             | van Gogh      |
| Der Park                 | Klingt        |
| Liegender Hund im Schnee | Marc          |
| Hauptweg und Nebenwege   | Klee          |
| Jungfrau im Baum         | Klee          |
| Das gelbe Haus           | Klee          |
+--------------------------+---------------+

Is it possible to align the left column to the right, like this:

+--------------------------+---------------+
| Title                    | Artist        |
+--------------------------+---------------+
|           Drei Musikanten| Picasso       |
|          Buveuse assoupie| Picasso       |
|         Die Flöte des Pan| Picasso       |
+--------------------------+---------------+

Thanks for your help!


Solution

  • If your Title length is 150 then query like this

     SELECT LPAD(Titel,150,' ') as Titel , KuenstlerName from Bild;
    

    Check Manual for LPAD function.