The following query is working absolutely fine for me:
SELECT * From Customers
WHERE Customers.ContactName = (SELECT FirstName
FROM Employees as E, orders as O
WHERE <condition>
LIMIT 1);
However, if i use LIKE
instead of =
to compare with the result of the subquery, I'm not getting any results.
How do I use LIKE '%%'
in the above query?
First, this query should not be working fine:
Because
WHERE LIMIT 1
is not proper SQL. And, you should learn to use properjoin
syntax. Presumably, you intend:You could conceivably add
LIKE
instead of=
and '%' in the subquery:But I would write this using
EXISTS
:This does not do exactly the same thing as your query. It does something more reasonable. Instead of comparing one random name from the subquery, it will determine if there are any matches in the subquery. That seems a more reasonable intention for the query.