user4099209
user4099209

Reputation:

SQL like with select statement

Is it possible to use LIKE with an if statement, like so:

SELECT orders.[order#] 
FROM orders 
WHERE orders.[order#] LIKE *(SELECT .. FROM .. WHERE .. = ..)*

The statement above results in a syntax error in Access 2016.

Upvotes: 0

Views: 262

Answers (2)

Parfait
Parfait

Reputation: 107767

Consider an implicit join using LIKE statement (or cross join with filter):

SELECT orders.[order#] 
FROM orders, (SELECT .. FROM .. WHERE .. = ..) AS t
WHERE orders.[order#] LIKE '*' & t.Col & '*'

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1271013

You can use a correlated subquery for this:

SELECT o.[order#]
FROM orders o
WHERE EXISTS (SELECT 1
              FROM . . .
              WHERE o.[order#] LIKE <whatever>
             );

Upvotes: 2

Related Questions