Peter
Peter

Reputation: 75

IN operator in SQL (PostgreSQL)

I'm trying to select with the IN operator in postgreSQL.

When I write:

select name from table where name = 'Eastway'

or

select name from table where name like '%Oxford%'

then I have multiple results but

select name from table where name in ('Eastway', '%Oxford%')

does not return any value.

What am I doing wrong? And apologies for newbie question.

Upvotes: 1

Views: 105

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

You can use or for this. Or a regular expression:

select name
from table
where name ~ '(^Eastway$)|Oxford';

Upvotes: 0

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48197

LIKE is a regular expresion comparasion

= is exact match

Your IN is equivalent to name ='Eastway' OR name = '%Oxford%'

But if you say on your first query you get multiple result. On your IN version should also have some result as well. The rows where name ='Eastway'

Upvotes: 2

Related Questions