How to avoid Cartesian product in an INNER JOIN query?
Posted
by flhe
on Stack Overflow
See other posts from Stack Overflow
or by flhe
Published on 2010-05-20T09:00:55Z
Indexed on
2010/05/20
9:10 UTC
Read the original article
Hit count: 431
I have 6 tables, let's call them a,b,c,d,e,f. Now I want to search all the colums (except the ID columns) of all tables for a certain word, let's say 'Joe'. What I did was, I made INNER JOINS over all the tables and then used LIKE to search the columns.
INNER JOIN ... ON INNER JOIN ... ON.......etc. WHERE a.firstname ~* 'Joe' OR a.lastname ~* 'Joe' OR b.favorite_food ~* 'Joe' OR c.job ~* 'Joe'.......etc.
The results are correct, I get all the colums I was looking for. But I also get some kind of cartesian product, I get 2 or more lines with almost the same results.
How can i avoid this? I want so have each line only once, since the results should appear on a web search.
© Stack Overflow or respective owner