w3resource

MySQL String Exercises: Get the employee id, email id

MySQL String: Exercise-7 with Solution

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

Sample table: employees


Code:

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

Sample Output:

employee_id	Email_ID
100		SK
101		NKOCH
102		LDEH
103		AHUN
104		BER
105		DAUS
106		VPATA
107		DLORE
108		NGREE
109		DFAV
110		JC
111		ISCIA
112		JMUR
113		LP
114		DRAPH
115		AK
116		SBA
117		STOB
118		GHIM
119		KCOLM
120		MWE
121		AFR
122		PKAUF
123		SVOLL
124		KMOUR
125		JNA
126		IMIKK
127		JLAN
128		SMAR
129		LBIS
130		MATKI
131		JAMR
132		TJOL
133		JMAL
134		MROG
135		K
136		HPHIL
137		RLAD
138		SSTI
139		J
140		JPA
141		TR
142		CDAV
143		RMA
144		PVAR
145		JRUS
146		KPART
147		AERRA
148		GCAMB
149		EZLOT
150		PTUC
151		DBERN
152		PH
153		COL
154		NCAMB
155		OTUVA
156		JK
157		PSU
158		AMCE
159		LSM
160		LDO
161		SSEW
162		CVISH
163		DGRE
164		MMARV
165		D
166		SA
167		ABA
168		LO
169		HBL
170		T
171		WSM
172		EBA
173		SKU
174		EA
175		AHUT
176		JTAY
177		JLIVI
178		KGR
179		CJOHN
180		WTAY
181		JFLE
182		MSULL
183		GGE
184		NSARC
185		AB
186		JDELL
187		ACAB
188		KCH
189		JDI
190		TGA
191		RPERK
192		SB
193		BEVER
194		SMCC
195		VJO
196		AWA
197		KFEE
198		DOCON
199		DGR
200		JWHA
201		MHART
202		P
203		SMAV
204		HB
205		SHIGG
206		WGI

MySQL Code Editor:

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.
Next:Write a query to find all employees where first names are in upper case.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.