Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 603
BlueFox Avatar asked Dec 12 '22 04:12

BlueFox


2 Answers

If your Title length is 150 then query like this

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

Check Manual for LPAD function.

like image 92
Sadikhasan Avatar answered Dec 27 '22 07:12

Sadikhasan


If Titel is 100 characters, then do this

SELECT
    LPAD(Titel, 100, ' '),
    ...

or

SELECT
    RIGHT(CONCAT(REPEAT(' ', 100), Titel), 100),
    ...
like image 42
gbn Avatar answered Dec 27 '22 09:12

gbn