Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check column if has the same value on all the rows

Tags:

mysql

How do I check if a column has all the rows the same value?

I don't think this will work.

SELECT column FROM table WHERE value = 1

I want to make, by time each row will turn from 0 to 1 till every row has value 1, if all the values are 1 to turn all in 0

id value
1  1
2  1
3  1
4  1
5  1
6  1
7  1
like image 756
Alex _TNT Avatar asked Oct 22 '15 07:10

Alex _TNT


People also ask

How do I select the same value in SQL?

To select duplicate values, you need to create groups of rows with the same values and then select the groups with counts greater than one. You can achieve that by using GROUP BY and a HAVING clause.


3 Answers

You can try to use distinct

select count(distinct column) FROM table 

If the result is 1 then it means there is only same value present in the column else there are different values present in your column.

like image 55
Rahul Tripathi Avatar answered Oct 12 '22 06:10

Rahul Tripathi


Try this query :-

select count(value) from table where value =0;

if rows return count is zero that means there are no zeroes in that column.

like image 29
Haseena Parkar Avatar answered Oct 12 '22 04:10

Haseena Parkar


Use count

SELECT count(value) as total FROM table

if total > 1 than more than on value

like image 27
Abhishek Sharma Avatar answered Oct 12 '22 04:10

Abhishek Sharma