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
From the following tables, write a SQL query to find those employees who work in a department where the employee’s first name contains the letter 'T'. Return employee ID, first name and last name.
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
Pictorial Presentation:

Practice Online
Query Visualization:
Duration:

Rows:

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: From the following tables, write a SQL query to find those employees who earn more than the average salary and work in a department with any employee whose first name contains a character a 'J'. Return employee ID, first name and salary.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
SQL: Tips of the Day
"where 1=1" statement?
It's usually when folks build up SQL statements.
When you add and value = "Toyota" you don't have to worry about whether there is a condition before or just WHERE.
Ref: https://bit.ly/3cayyhJ
- Exercises: Weekly Top 12 Most Popular Topics
- Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
- SQL Exercises, Practice, Solution - SUBQUERIES
- C Programming Exercises, Practice, Solution : For Loop
- Python Exercises, Practice, Solution
- Python Data Type: List - Exercises, Practice, Solution
- C++ Basic: Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - exercises on Employee Database
- SQL Exercises, Practice, Solution - exercises on Movie Database
- SQL Exercises, Practice, Solution - exercises on Soccer Database
- C Programming Exercises, Practice, Solution : Recursion