How to align a column right-adjusted

BlueFox picture BlueFox · Jul 2, 2014 · Viewed 27.1k times · Source

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!

Answer

Sadikhasan picture Sadikhasan · Jul 2, 2014

If your Title length is 150 then query like this

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

Check Manual for LPAD function.