sql - How to construct query which compares two sets in M:N relationship? -


i have 2 (three-the third binding table) tables user , feature. in many-to-many relationship. construct query finds users have similar features particular user.

i know can use this:

select user user user  inner join user.feature feature feature in :features 

but works when looking 1 specific feature. there way how in way of comparing "two sets" "features in features" in sql? or have in business layer?

you can use sql this. if understand, want rank other users how many features have in common given user.

select uf.user, count(*) featuresincommon user_features uf join      user_features uf2      on uf.feature = uf2.feature uf2.user = $user group uf.user order featuresincommon desc; 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -