

- 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
MySQL query to get the count of rows in which two or more specified values appear?
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 Questions & Answers
- MySQL Query to get count of unique values?
- Get count of values that only appear once in a MySQL column?
- How to find the minimum values of two or more fields in MySQL?
- MySQL query to multiply values of two rows and add the result
- How can we combine the values of two or more columns of MySQL table?
- Get the count of two table fields in a single MySQL query?
- MySQL query to count where more than three columns values are true?
- Count rows having three or more rows with a certain value in a MySQL table
- How to count rows from two tables in a single MySQL query?
- How to get number of rows in a table without using count(*) MySQL query?
- MySQL query to return only the rows which are numeric?
- MySQL query to count rows in multiple tables
- Can I insert two or more rows in a MySQL table at once?
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- How to get the max of two values MySQL?
Advertisements