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

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

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