With SQL can you use a sub-query in a WHERE LIKE clause?
Posted
by Jason
on Stack Overflow
See other posts from Stack Overflow
or by Jason
Published on 2010-03-27T10:14:15Z
Indexed on
2010/03/27
10:23 UTC
Read the original article
Hit count: 193
I'm not even sure how to even phrase this as it sounds weird conceptually, but I'll give it a try. Basically I'm looking for a way to create a query that is essentially a WHERE IN LIKE SELECT statement.
As an example, if I wanted to find all user records with a hotmail.com email address, I could do something like:
SELECT UserEmail
FROM Users
WHERE (UserEmail LIKE '%hotmail.com')
But what if I wanted to use a subquery as the matching criteria? Something like this:
SELECT UserEmail
FROM Users
WHERE (UserEmail LIKE (SELECT '%'+ Domain FROM Domains))
Is that even possible? If so, what's the right syntax?
© Stack Overflow or respective owner