Are there any performance concerns of note when using MySQL's CONCAT() function in a select query? Is it faster/slower/negligible to do a simple select, and format strings for a view using PHP after the result set from the database is returned? Or is a more complicated SQL query with multiple calls to CONCAT() that returns a string already formatted for the view a better approach?
ie is this:
select CONCAT(lastname, ', ', firstname) from people;
Faster/Slower/No difference from this:
<?php
$query = 'Select lastname, firstname from people';
...
$name = $data['lastname'] . ', ' . $data['firstname']; //OR
$name = sprintf("%s, %s", $data['lastname'], $data['firstname']);
?>
You're better off in almost all cases by doing filtering and data massaging with the SQL engine versus on the web server.
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