Answer: String Comparison
Find a detailed explanation about string comparison in SQL.
Solution
The solution is given below:
Press + to interact
-- The query to find employees with either "J" or "H," but not both, in their namesSELECT EName AS "Employee Name" FROM EmployeesWHERE (EName LIKE '%J%' AND EName NOT LIKE '%H%')OR (EName LIKE '%H%' AND EName NOT LIKE '%J%');
Code explanation
The explanation of the solution code is given below:
Line 2: The
SELECT
statement selects the columnEName
from the tableEmployees
. We useAS
to set an alias for the column.Lines 3–4: The
WHERE
clause specifies the condition on which we want to retrieve the data from the table. Here, we use theLIKE
andNOT LIKE
operator to filter the names that containJ
but notH
, orH
but notJ
.
Recalling relevant concepts
We have covered the following concepts in this question:
Selective columns
Aliases
Filtering ...
Access this course and 1400+ top-rated courses and projects.