如何使用活动记录codeigniter根据匹配记录数量的减少从用户表中获取记录

i am having two tables one is the user answers in which users answers some questions about himself

user_id   question_id  answer_id
1             2            3
1             4            2
1             2            1
1             2            3
1             4            1
2             2            3
2             4            2
2             2            1
2             2            3
2             4            1

the other one is the prefernce table in which the user answers about his partner

 user_id    question_id    answer_id
    1             2             3
    1             4             2
    1             2             1

what i need to do is first i have to take question_id and answer_id for a particular user from the second table and match the question_id and answer_id to the first table and we need to fetch the user detail from the third table on the basis of decreasing number of answer matched for that user to the other.