
- 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 fetch records where decimal is a whole number
For this, use FLOOR() function. Here, we will be fetching records like 12.00, 35.00, etc. from a list with records like 5.23, 8.76, 12.00, 22.68, etc. Let us first create a table −
mysql> create table DemoTable ( Value DECIMAL(4,2) ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(54.20); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(55.0); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(7.8); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(9.0); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(9.2); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 54.20 | | 55.00 | | 7.80 | | 9.00 | | 9.20 | +-------+ 5 rows in set (0.00 sec)
Following is the query to fetch records where decimal is a whole number −
mysql> select *from DemoTable where Value=floor(Value);
This will produce the following output −
+-------+ | Value | +-------+ | 55.00 | | 9.00 | +-------+ 2 rows in set (0.02 sec)
- Related Articles
- MySQL query to find a match and fetch records
- MySQL query to fetch records from a range of months?
- MySQL query to fetch records wherein timestamp is before 15+ days?
- MySQL query to fetch records before currentdate + 2 weeks?
- MySQL query to fetch the latest date from a table with date records
- Remove decimal from records and sum them using a MySQL query
- MySQL query for text search with LIKE and OR to fetch records
- MySQL RegExp to fetch records with only a specific number of words
- Write a MySQL query where length of the records is longer than 1?
- MySQL query to fetch specific records matched from an array (comma separated values)
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- MongoDB query to fetch date records (ISODate format) in a range
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL db query to fetch records from comma separate values on the basis of a specific value
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?

Advertisements