Darryl Hein
Darryl Hein

Reputation: 144947

checking to ensure all values in a field are integers in MySQL

I have a column that is currently a floating-point number and I need to check if all the values in the column are integers. What's the easiest way to do this?

Upvotes: 0

Views: 129

Answers (2)

Jase Whatson
Jase Whatson

Reputation: 4207

And to specifically find the records that are not integers...

SELECT * from yourtable WHERE col % 1 != 0;

Upvotes: 1

Andy West
Andy West

Reputation: 12499

SELECT COUNT(*) FROM yourtable WHERE ceil(yourcolumn) != yourcolumn

If the count > 0 then there are non-integer values.

Upvotes: 2

Related Questions