
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find string count of a particular id in a column using a MySQL query?
For this, use the CHAR_LENGTH() function in MySQL. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Subject longtext ); Query OK, 0 rows affected (1.17 sec)
Now you can insert some records in the table using insert command −
mysql> insert into DemoTable(Subject) values('MySQL,MongoDB'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Subject) values('MySQL,MongoDB'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Subject) values('MySQL'); Query OK, 1 row affected (0.15 sec) Display all records from the table using select statement : mysql> select *from DemoTable;
Output
+----+---------------+ | Id | Subject | +----+---------------+ | 1 | MySQL,MongoDB | | 2 | MySQL,MongoDB | | 3 | MongoDB | | 4 | MySQL | +----+---------------+ 4 rows in set (0.00 sec)
Following is the query to find string count with a MySQL query of a particular id in a column. We are checking for id 1 here −
mysql> select Id,char_length(Subject) - char_length(REPLACE((Subject), ',', ''))+1 AS FreqSubject from DemoTable WHERE char_length(Subject) > 0 AND Id = 1;
Output
+----+-------------+ | Id | FreqSubject | +----+-------------+ | 1 | 2 | +----+-------------+ 1 row in set (0.02 sec)
- Related Questions & Answers
- How to increment all the rows of a particular column by 1 in a single MySQL query (ID column +1)?
- How to find a particular varchar id in MySQL from a list of values?
- How to find the count of a particular character in a string vector in R?
- Updating last entry of a particular ID in MySQL
- MySQL query to count the duplicate ID values and display the result in a separate column
- How to replace a particular character in a MySQL column?
- MySQL query to count rows with a specific column?
- Get count of how many times a string appears in a MySQL column?
- MySQL query to get the count of distinct records in a column
- MySQL query to count number of duplicate values in a table column
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- How to count the number of occurrences of a specific value in a column with a single MySQL query?
- How to find the frequency of a particular string in a column based on another column in an R data frame using dplyr package?
- How to find and replace string in MySQL database for a particular string only?
- MySQL query to sum the values of similar columns from two different tables for a particular ID
Advertisements