Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of rows in which two or more specified values appear

Tags:

sql

mysql

I have the following table:

n1|n2|n3|n4|n5
 1| 5| 4| 7|26
26|80|75| 1|10
 5| 3| 2| 1|4
45|26| 1| 3|66

I'm trying to get the number of rows in which two or more specified values appear. In the above table, for example, 26 and 1 appear in 3 rows.

Is there a fast way to do this in mySQL or should I build some function in PHP?

Thank you very much for your help

like image 617
Floppy88 Avatar asked Aug 27 '12 09:08

Floppy88


People also ask

Which SQL function is used to count the number of rows in a SQL query?

The SQL COUNT( ) function is used to return the number of rows in a table. It is used with the Select( ) statement.

How can we get the number of records or rows in a table using mysql?

To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.


1 Answers

SELECT COUNT(*) FROM your_table
WHERE 1 IN (n1,n2,n3,n4,n5) AND 26 IN (n1,n2,n3,n4,n5)
like image 96
xdazz Avatar answered Sep 18 '22 05:09

xdazz