Tag: query
How to get multiple counts in single MySQL query
This article will be taking an example table customer_data and will try to get multiple counts from this table within a single query. Topics covered: COUNT(*) GROUP BY COUNT(DISTINCT) BASED ON CONDITION Let us get started by creating the table customer_data and inserting the data into it. CREATE TABLE customer_data ( customer_id INT , customer_name VARCHAR(255), customer_address VARCHAR(255), customer_level …
Count with If Condition in MySQL Query
Count() function in MySQL is to get the number of rows in a MySQL table or expression. In this article, we will talk about the count() function with if(). We are creating a table students_data followed by adding data to it. CREATE TABLE students_data ( student_id INT AUTO_INCREMENT, student_name VARCHAR(255), student_address VARCHAR(255), student_grade VARCHAR(255), student_subject VARCHAR(255), PRIMARY …
MySQL string contains query
This article will look into how to get the data from MySQL tables where a column contains a particular string. We will be illustrating the concept using various examples and different methods. Table of Contents:- MySQL query string contains using ‘%’ wildcard MySQL query string contains using LOCATE MySQL query string contains using INSTR Let …