EducationSelecting and updating first character of the first word in upper-case in...

Selecting and updating first character of the first word in upper-case in MySQL

Unlike PHP and ASP which has the inbuilt function to convert the first character of the first word in the upper case of a given string type, MySQL lacks this feature though you can have your inbuilt custom code to do so. See below two examples on how to select and update the first character of the first word in the upper case in MySQL command-line as well as in phpMyAdmin.

How to Select First Character of First Word to Upper Case in MySQL?

MySQL command-line, as well as phpMyAdmin, do not offer the facility to select the first character of the first letter to the upper case. Using below to customise MySQL  Query you can select the first character of the first letter to the upper case —

select concat(upper(left(column_name,1)),substring(column_name,2)) from table_name;

How to Update the First Character of First Word to Upper Case in MySQL?

It is straightforward to update the records once you have run the above snippet successfully — all you need to change the parameter of the query to update your records. You can use the following MySQL query to update your records with the changes.

update table_name set column_name=concat(upper(left(column_name,1)),substring(column_name,2));

Capitalising with PHP and MySQL?

PHP has the inbuilt function to capitalise the first character of the first letter using the function ucfirst. See below for an example: –

$sql = "SELECT name FROM students";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo ucfirst($row["name"]);
    }
} else {
    echo "0 results";
}

IR Media Team
IR Media Team
IR Media Team is a member of Digital Pradesh News Networks, a collective of journalists, reporters, writers, editors, lawyers, advocates, professors, and scholars affiliated with the Digital Pradesh News Networks.

Latest Updates