I'm executing a SELECT query on a table in MySQL using the command-line interface (not a GUI client):
SELECT * FROM blog_entry;
One of blog_entry's fields is of type 'longtext' and is such a long piece of text that when the result is displayed in my terminal the display of rows takes more than one line. This causes an ugly mess of a display, where columns aren't easily visible. What technique can I use in my SELECT query that would limit the number of characters displayed for each field so that the printed row results don't overflow to new lines?
Use MySQL's SUBSTRING
function, as described in the documentation. Like:
SELECT SUBSTRING(`text`, 1, 100) FROM blog_entry;
To select first 100 chars.
You can use the LEFT()
function to get only the first characters:
SELECT LEFT(LongField, 20) AS LongField_First20chars FROM ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With