
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get the size of selected rows in MySQL
To get the size of selected rows, use CHAR_LENGTH(). Let us first create a table −
mysql> create table DemoTable1612 -> ( -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.87 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1612 values('David','Brown'); Query OK, 1 row affected (0.75 sec) mysql> insert into DemoTable1612 values('John','Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1612 values('Bob','Taylor'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1612;
This will produce the following output −
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | David | Brown | | John | Smith | | Bob | Taylor | +-----------+----------+ 3 rows in set (0.00 sec)
Following is the query to get the size of selected rows in MySQL −
mysql> select sum(char_length(FirstName)) from DemoTable1612 where LastName IN('Brown','Smith','Taylor');
This will produce the following output −
+-----------------------------+ | sum(char_length(FirstName)) | +-----------------------------+ | 12 | +-----------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Display multiple selected rows using MySQL IN()
- Get the sum of a column in all MySQL rows?
- Get at least x number of rows in MySQL?
- Get the count of only unique rows in a MySQL column?
- Get the number of rows in a particular table with MySQL
- Get rows with GROUP BY in MySQL?
- Get total number of rows while using LIMIT in MySQL?
- How to get the size of the tables of a MySQL database?
- Can we get total number of rows in a MySQL database?
- Easiest way to get number of rows in a MySQL table?
- Specify the size of the rows in a CSS grid layout
- How to get selected Index of the Radio group in Android?
- How to get the index of selected option in Tkinter Combobox?
- How can we get all the unique rows in MySQL result set?
- How can we get the total number of rows affected by MySQL query?

Advertisements