Is a query with intersect equivalent to those 'where a and b'? Is a query with intersect equivalent to those 'where a and b'? postgresql postgresql

Is a query with intersect equivalent to those 'where a and b'?


WHERE (a) AND (b) is a boolean condition applied to Every record. A record only gets included if it satisfies the whole condition. In other words, only records where word is 'france' AND part is 'headline' at the same time will be included.


Is what you need more similar to using an OR in your condition?

select page from title where word = 'france' or part = 'headline';


Or are you having problems due to there being multiple records referencing the same page?

For example...

1 | 'france'  | 'aaa' | 'headline'2 | 'france'  | 'bbb' | 'body'3 | 'germany' | 'bbb' | 'headline'

'aaa' will be returned by both your queries.

'bbb' will be returned by only your second query.


The only technical difference I see is that intersect operation would generate unique pages. The first may generate duplicates.

Update:They aren't the same.the correct answer is what Dems already explained(I voted his answer):

page  word     part1     france   headline2     uk       headline2     france   body

word = france AND part = headline => page 1

word = france => page 1, 2 part = headline => page 1, 2

intersection of previous two sets => page 1, 2

Update2: Response to question: how to make intersect give the same result?The intersect must be done over column in conditions, as here.

select page, word, part from title where word = 'france' intersect select page, word, part from title where part = 'headline'