MySQL Output Formatting: Top 3 Methods
In MySQL, you can format the output results using the following methods:
- Save the result to a file
For example:
SELECT * INTO OUTFILE '/path/to/file.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM table_name;
- Join or combine
For example:
SELECT CONCAT(column1, ', ', column2, ', ', column3) AS formatted_output
FROM table_name;
- Converts a value to a specific format.
For example:
SELECT FORMAT(column_name, 2) AS formatted_output
FROM table_name;
These methods can output query results in different formats as needed, making them easier to read and understand.