mysql - Selecting Distinct rows When there is a Logical OR with two columns -


as title suggests have mysql query this:

select distinct `friendly_url` `post` `description` ? or `heading` ? order `friendly_url` 

i have given string '%' wild card in parameters works search function. how ever, user searching common word 'is' , appears in both heading , description in same post. query returns same post twice. don't want happen, hence 'distinct'.

why happen? way can work around make work way want?

the query not returning same row twice. predicates in where clause evaulated against each row, , either row returned, or it's not. no combination of or conditions going cause mysql return "same row" multiple times.

if getting duplicate values of friendly_url, have multiple rows in post table have same value friendly_url. (i.e. friendly_url column not unique in post table.)


you don't have use distinct keyword remove duplicates resultset. remove distinct keyword, , add group friendly_url before order by clause.


to identify "duplicated" values of friendly_url, , how many rows have same value:

  select p.friendly_url        , count(1)     post p    group p.friendly_url   having count(1) > 1 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -