Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PostgreSQL String() Function: Get the employee id, email id to discard the last three characters


7. Write a query to get the employee id, email id to discard the last three characters.

Sample Solution:

Code:

SELECT employee_id, REVERSE(SUBSTR(REVERSE(email), 4)) as Email_ID 
FROM employees;

Sample table: employees


Output:

postgres=# SELECT employee_id, SUBSTR(REVERSE(email), 4) as Email_ID
postgres-# FROM employees;
 employee_id | email_id
-------------+----------
         100 | KS
         101 | HCOKN
         102 | HEDL
         103 | NUHA
         104 | REB
         105 | SUAD
         106 | ATAPV
         107 | EROLD
         108 | EERGN
         109 | VAFD
         110 | CJ
         111 | AICSI
         112 | RUMJ
         113 | PL
         114 | HPARD
         115 | KA
         116 | ABS
         117 | BOTS
         118 | MIHG
         119 | MLOCK
         120 | EWM
         121 | RFA
         122 | FUAKP
         123 | LLOVS
         124 | RUOMK
         125 | ANJ
         126 | KKIMI
         127 | NALJ
		...  | ...
         197 | EEFK
         198 | NOCOD
         199 | RGD
         200 | AHWJ
         201 | TRAHM
         202 | P
         203 | VAMS
         204 | BH
         205 | GGIHS
         206 | IGW
(107 rows)

Practice Online


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query to get the employee id, first name and hire month of an employee.
Next: Write a query to find all the employees which first name contains all the uppercase letter.

What is the difficulty level of this exercise?