
- SQL Tutorial
- SQL - Home
- SQL - Overview
- SQL - RDBMS Concepts
- SQL - Databases
- SQL - Syntax
- SQL - Data Types
- SQL - Operators
- SQL - Expressions
- SQL Database
- SQL - Create Database
- SQL - Drop Database
- SQL - Select Database
- SQL - Rename Database
- SQL - Show Databases
- SQL - Backup Database
- SQL Table
- SQL - Create Table
- SQL - Show Tables
- SQL - Rename Table
- SQL - Truncate Table
- SQL - Clone Tables
- SQL - Temporary Tables
- SQL - Alter Tables
- SQL - Drop Table
- SQL - Delete Table
- SQL - Constraints
- SQL Queries
- SQL - Insert Query
- SQL - Select Query
- SQL - Select Into
- SQL - Insert Into Select
- SQL - Update Query
- SQL - Delete Query
- SQL - Sorting Results
- SQL Views
- SQL - Create Views
- SQL - Update Views
- SQL - Drop Views
- SQL - Rename Views
- SQL Operators and Clauses
- SQL - Where Clause
- SQL - Top Clause
- SQL - Distinct Clause
- SQL - Order By Clause
- SQL - Group By Clause
- SQL - Having Clause
- SQL - AND & OR
- SQL - BOOLEAN (BIT) Operator
- SQL - LIKE Operator
- SQL - IN Operator
- SQL - ANY, ALL Operators
- SQL - EXISTS Operator
- SQL - CASE
- SQL - NOT Operator
- SQL - NOT EQUAL
- SQL - IS NULL
- SQL - IS NOT NULL
- SQL - NOT NULL
- SQL - BETWEEN Operator
- SQL - UNION Operator
- SQL - UNION vs UNION ALL
- SQL - INTERSECT Operator
- SQL - EXCEPT Operator
- SQL - Aliases
- SQL Joins
- SQL - Using Joins
- SQL - Inner Join
- SQL - Left Join
- SQL - Right Join
- SQL - Cross Join
- SQL - Full Join
- SQL - Self Join
- SQL - Delete Join
- SQL - Update Join
- SQL - Left Join vs Right Join
- SQL - Union vs Join
- SQL Keys
- SQL - Unique Key
- SQL - Primary Key
- SQL - Foreign Key
- SQL - Composite Key
- SQL - Alternate Key
- SQL Indexes
- SQL - Indexes
- SQL - Create Index
- SQL - Drop Index
- SQL - Show Indexes
- SQL - Unique Index
- SQL - Clustered Index
- SQL - Non-Clustered Index
- Advanced SQL
- SQL - Wildcards
- SQL - Comments
- SQL - Injection
- SQL - Hosting
- SQL - Min & Max
- SQL - Null Functions
- SQL - Check Constraint
- SQL - Default Constraint
- SQL - Stored Procedures
- SQL - NULL Values
- SQL - Transactions
- SQL - Sub Queries
- SQL - Handling Duplicates
- SQL - Using Sequences
- SQL - Auto Increment
- SQL - Date & Time
- SQL - Cursors
- SQL - Common Table Expression
- SQL - Group By vs Order By
- SQL - IN vs EXISTS
- SQL - Database Tuning
- SQL Function Reference
- SQL - Date Functions
- SQL - String Functions
- SQL - Aggregate Functions
- SQL - Numeric Functions
- SQL - Text & Image Functions
- SQL - Statistical Functions
- SQL - Logical Functions
- SQL - Cursor Functions
- SQL - JSON Functions
- SQL - Conversion Functions
- SQL - Datatype Functions
- SQL Useful Resources
- SQL - Questions and Answers
- SQL - Quick Guide
- SQL - Useful Functions
- SQL - Useful Resources
- SQL - Discussion
SQL - LOG10() Function
The SQL LOG10() Is a mathematical function that is used in the SQL to retrieve the natural logarithm of a specified number to the base-10.
Syntax
Following is the syntax of the SQL LOG10() function −
LOG10(X);
Parameters
X − is the numeric value required to calculate the natural logarithm of base 10.
Syntax
Following is the syntax to use the LOG10() in the SQL table −
SELECT column_name, LOG10(X) AS alias_name From table_name;
In the above SQL query, we can pass the column name from the table in which we want to perform the LOG10() function.
Example
In the following example, we are calculating of log(10) to the base 10. It returns 1.
SELECT LOG10(10) AS 'log10';
Output
Following is the output of the above −
+-------+ | log10 | +-------+ | 1 | +-------+
Example
In the following example, we are passing 0 and a negative value to the LOG10() function if the value passed is 0 and a negative. Log10 will return a value null. In MySQL, it gives an error in the SQL.
Following is the query −
SELECT lOG10(0) AS 'LOG(0)', LOG10(-2) AS 'LOG(-2)';
Output
On execution of the above SQL query, we get the error because the LOG10() function in SQL returns an error if the argument is 0 or a negative value.
An invalid floating point operation occurred.
Example
In the following example, we are finding the value of log10(1) using the SQL Log10() function.
SELECT LOG10(1) AS log1;
Output
When we execute the above SQL query, we get 0 because log1 always returns 0.
+------+ | log1 | +------+ | 0 | +------+
Example
In the following example, we are passing the floating-point number and also passing the string-type number in the SQL log10() function.
SELECT lOG10('4') AS log4, LOG10(255.255) AS log_Of_Floatvalue;
Output
Following is the output of the above SQL query −
+--------------------+-------------------+ | log4 | log_Of_Floatvalue | +--------------------+-------------------+ | 0.602059991327962 | 2.40697425791327 | +--------------------+-------------------+
Example
In the following example, we are using the emp_tbl to fetch the ID and name and perform the LOG10(). Here, we are calculating the LOG10 value of the ID of the emp_tbl table.
Let’s create a table named emp_tbl −
Create table emp_tbl (ID INT NOT NULL, NAME VARCHAR(20), ACCOUNT_BL NUMERIC);
Let’s insert n data into table &mins;
insert into emp_tbl values(1, 'Raja', 1200); insert into emp_tbl values(2, 'Vivek', 1500); insert into emp_tbl values(3, 'Roja', -1500); insert into emp_tbl values(4, 'Lukha', -1700); insert into emp_tbl values(5, 'Sonal', 1800);
Let’s fetch the table details.
SELECT * FROM emp_tbl;
Following is the emp_tbl table −
+----+-------+------------+ | ID | NAME | ACCOUNT_BL | +----+-------+------------+ | 1 | Raja | 1200 | | 2 | Vivek | 1500 | | 3 | Roja | -1500 | | 4 | Lukha | -1700 | | 5 | Sonal | 1800 | +----+-------+------------+
Following is the query to Fetch the Name, ID and calculate the LOG10() of the ID −
SELECT NAME, ID, LOG10(ID) log_Of_ID from emp_tbl;
Output
Following is the output of the above SQL query −
+-------+----+---------------------+ | NAME | ID | log_Of_ID | +-------+----+---------------------+ | Raja | 1 | 0 | | Vivek | 2 | 0.3010299956639812 | | Roja | 3 | 0.47712125471966244 | | Lukha | 4 | 0.6020599913279624 | | Sonal | 5 | 0.6989700043360189 | +-------+----+---------------------+