
- 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 set currency records
Use FORMAT() in MySQL to display currency records and display them in the correct form. Let us first create a table −
mysql> create table DemoTable -> ( -> Amount DECIMAL(15,4) -> ); Query OK, 0 rows affected (0.75 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(90948484); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000000000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1535353536); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(773646463); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------------+ | Amount | +-----------------+ | 90948484.0000 | | 1000000000.0000 | | 1535353536.0000 | | 773646463.0000 | +-----------------+ 4 rows in set (0.00 sec)
Here is the query to set currency in MySQL −
mysql> select concat('USD ',format(Amount,2)) as Currency from DemoTable;
This will produce the following output. Here, we are displaying USD currency records in the correct format−
+----------------------+ | Currency | +----------------------+ | USD 90,948,484.00 | | USD 1,000,000,000.00 | | USD 1,535,353,536.00 | | USD 773,646,463.00 | +----------------------+ 4 rows in set (0.23 sec)
- Related Articles
- Display USD currency records with the correct format in MySQL
- MySQL query to select top 10 records?
- MySQL query to select bottom n records
- MySQL query to insert multiple records quickly
- Set different IDs for records with conditions using a single MySQL query
- MySQL query to return 5 random records from last 20 records?
- MySQL query to select records with a particular date?
- MySQL query to remove Null Records in a column?
- MySQL query to find alternative records from a table
- MySQL query to find a match and fetch records
- MySQL query to display records ordered by numeric difference?
- MySQL query to alphabetize records and count the duplicates?
- MySQL query to fetch records before currentdate + 2 weeks?
- MySQL query to update all records to capitalize only the first letter and set all others in lowercase
- MySQL query to count records that begin with specific letters

Advertisements