w3resource
SQL exercises

SQL Subquery Exercises: Display the employee ID and name of all employees who works in such a department where the employees are working whose name containing a letter 'T'

SQL SUBQUERY : Exercise-14 with Solution

Write a query to display the employee ID and name ( first name and last name ) of all employees who works in such a department where the employees are working whose name containing a letter 'T'.

Sample table: employees


Sample Solution:

SELECT employee_id, first_name, last_name  
FROM employees  
WHERE department_id IN  
( SELECT department_id  
FROM employees  
WHERE first_name LIKE '%T%' );

Sample Output:

employee_id	first_name	last_name
120		Matthew		Weiss
121		Adam		Fripp
122		Payam		Kaufling
123		Shanta		Vollman
124		Kevin		Mourgos
125		Julia		Nayer
126		Irene		Mikkilineni
127		James		Landry
128		Steven		Markle
129		Laura		Bissot
130		Mozhe		Atkinson
131		James		Marlow
132		TJ		Olson
133		Jason		Mallin
134		Michael		Rogers
135		Ki		Gee
136		Hazel		Philtanker
137		Renske		Ladwig
138		Stephen		Stiles
139		John		Seo
140		Joshua		Patel
141		Trenna		Rajs
142		Curtis		Davies
143		Randall		Matos
144		Peter		Vargas
145		John		Russell
146		Karen		Partners
147		Alberto		Errazuriz
148		Gerald		Cambrault
149		Eleni		Zlotkey
150		Peter		Tucker
151		David		Bernstein
152		Peter		Hall
153		Christopher	Olsen
154		Nanette		Cambrault
155		Oliver		Tuvault
156		Janette		King
157		Patrick		Sully
158		Allan		McEwen
159		Lindsey		Smith
160		Louise		Doran
161		Sarath		Sewall
162		Clara		Vishney
163		Danielle	Greene
164		Mattea		Marvins
165		David		Lee
166		Sundar		Ande
167		Amit		Banda
168		Lisa		Ozer
169		Harrison	Bloom
170		Tayler		Fox
171		William		Smith
172		Elizabeth	Bates
173		Sundita		Kumar
174		Ellen		Abel
175		Alyssa		Hutton
176		Jonathon	Taylor
177		Jack		Livingston
179		Charles		Johnson
180		Winston		Taylor
181		Jean		Fleaur
182		Martha		Sullivan
183		Girard		Geoni
184		Nandita		Sarchand
185		Alexis		Bull
186		Julia		Dellinger
187		Anthony		Cabrio
188		Kelly		Chung
189		Jennifer	Dilly
190		Timothy		Gates
191		Randall		Perkins
192		Sarah		Bell
193		Britney		Everett
194		Samuel		McCain
195		Vance		Jones
196		Alana		Walsh
197		Kevin		Feeney
198		Donald		OConnell
199		Douglas		Grant

Practice Online


Query Visualization:

Duration:

Query visualization of Display the employee ID and name of all employees who works in such a department where the employees are working whose name containing a letter 'T' - Duration

Rows:

Query visualization of Display the employee ID and name of all employees who works in such a department where the employees are working whose name containing a letter 'T' - Rows

Cost:

Query visualization of Display the employee ID and name of all employees who works in such a department where the employees are working whose name containing a letter 'T' - Cost

Contribute your code and comments through Disqus.

Previous: Write a query to display the employee name( first name and last name ) and hiredate for all employees in the same department as Clara. Exclude Clara.
Next: Write a query to display the employee number, name( first name and last name ), and salary for all employees who earn more than the average salary and who work in a department with any employee with a 'J' in their name.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming