
- 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
MySQL query to get the count of rows in which two or more specified values appear?n
To get the count of rows in which two or more specified values appear, let us first create a sample table:
mysql> create table specifiedValuesDemo -> ( -> Value int, -> Value2 int, -> Value3 int -> ); Query OK, 0 rows affected (0.60 sec)
Following is the query to insert some records in the table using insert command:
mysql> insert into specifiedValuesDemo values(10,15,20); Query OK, 1 row affected (0.17 sec) mysql> insert into specifiedValuesDemo values(40,10,20); Query OK, 1 row affected (0.16 sec) mysql> insert into specifiedValuesDemo values(80,20,1000); Query OK, 1 row affected (0.12 sec)
Following is the query to display records from the table using select command:
mysql> select *from specifiedValuesDemo;
This will produce the following output
+-------+--------+--------+ | Value | Value2 | Value3 | +-------+--------+--------+ | 10 | 15 | 20 | | 40 | 10 | 20 | | 80 | 20 | 1000 | +-------+--------+--------+ 3 rows in set (0.00 sec)
Let us get the count of rows in which two or more specified values appear:
mysql> select count(*) from specifiedValuesDemo -> where 10 in(Value,Value2,Value3) and 20 in(Value,Value2,Value3);
This will produce the following output
+----------+ | count(*) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL Query to get count of unique values?
- Get count of values that only appear once in a MySQL column?
- MySQL query to multiply values of two rows and add the result
- How to get number of rows in a table without using count(*) MySQL query?
- How to count rows from two tables in a single MySQL query?
- MySQL query to count where more than three columns values are true?
- MySQL query to count rows in multiple tables
- Get the count of two table fields in a single MySQL query?
- How to find the minimum values of two or more fields in MySQL?
- Count rows having three or more rows with a certain value in a MySQL table
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- MySQL query to get the count of values and display the count in a new column ordered in descending order\n
- Get multiple count in a single MySQL query for specific column values
- MySQL query to count rows with a specific column?
- MySQL query to sum up values of rows and sort the result?

Advertisements