SQL RIGHT() Function


The SQL RIGHT() is a function, and extracts substring or number of characters from a given input string or text.

The SQL RIGHT() function is extracts data or substring from RIGHT most character.

The SQL RIGHT() function is supports or work with character and numeric based columns.

It can be used in any valid SQL SELECT statement as well in SQL where clause.


SQL RIGHT() Syntax

The below syntax is used to extracts substring or number of characters from a given input string or text.


SELECT RIGHT(string or text, number_of_characters);

The below syntax is used to extracts substring or number of characters from a given table column or field.


SELECT RIGHT(column_name1, number_of_characters) FROM table_name;


SQL RIGHT() Example - Using Expression Or Formula

The following SQL SELECT statement will extract number of characters of a given input string or text.


SELECT RIGHT('I am fine', 7) AS 'Read 7 chars from right side';

The result of above query is:

Read 7 chars from right side
am fine

SQL RIGHT() More Example

Input Value Result
RIGHT('Hi ... Hello', 2) lo
RIGHT('it's nice database tutorial!', 13) base tutorial!
RIGHT('12345', 3) 543

Sample Database Table - Books

BookId BookName BookPrice RelYear DomainName AuthorName
1 Professional Microsoft SQL Server 140 2010 Security Keshavan
2 Beginning SQL Queries 75 2015 Programming Harish Karthik
3 MySql Concurrency 199.97 2014 Administration Vinoth Kumar
4 From Access To SQL Server 100 2015 Administration Vidyavathi
5 Oracle Database 11G New Features 175 2012 Database Azaghu Varshith
6 Oracle PL/sql By Example 123.45 2009 Database Varshini Kutty
7 The Complete Guide to SQL Server 110 2013 Security Rishi Keshan
8 My SQL Complete Reference 190 2011 Security Varshini Kutty
9 Jump Start MySQL 95 2013 Programming Vidyavathi
10 Oracle Cookbook 125 2015 Security Vidyavathi
11 Programming With MySQL 200 2013 Performance Vidyavathi
12 Simply Oracle 178.69 2012 Optimization Siva Kumar

SQL RIGHT() Example - With Table Column

The following SQL statement selects the "BookID", "BookName" and "RelYear" fields from the "Books" table, and extract the specified number of characters from "Books" table:


SELECT BookID,
RIGHT(BookName, 6) As 'Book Name Last 6 Char(s)',
RIGHT(RelYear, 2) As 'Author Name Last 2 Char(s)' 
FROM Books;

The result of above query is:

BookID Book Name Last 6 Char(s) Author Name Last 2 Char(s)
1 Server 10
2 ueries 15
3 rrency 14
4 Server 15
5 atures 12
6 xample 09
7 Server 13
8 erence 11
9 MySQL 13
10 okbook 15
11 MySQL 13
12 Oracle 12

Search Keys

  • sql select right characters
  • sql right of character
  • right function in sql
  • sql string functions with examples
  • sql query string functions
  • sql string functions examples
  • string functions in sql server
  • sql select substring