1

How can I write this SQL using cakephp find()

SELECT a.user_id FROM answers a INNER JOIN answers a1 ON a1.question_id=1 AND a1.answer_value='Pooch' INNER JOIN answers a2 ON a2.question_id=2 AND a2.answer_value='Peach' GROUP BY a.user_id 

Thanks in advance

2
  • try this: stackoverflow.com/questions/806650/… Commented Sep 20, 2011 at 14:50
  • I need to join the same table with different criteria Commented Sep 20, 2011 at 14:59

3 Answers 3

0

You can use ad hoc joins or set up a self-referential model association. The former may be the easiest option because it's just building the SQL you already know and understand. :-)

Sign up to request clarification or add additional context in comments.

Comments

0

There is a good section of the cookbook that shows you how to join tables, that dont automatically happen through your associations (hasOne, hasMany) etc.

http://book.cakephp.org/view/1047/Joining-tables

1 Comment

I've read that but it doesn't help. I need to join the same table multiple times
0

You can use converter by dogmatic69 here : http://cakephptutor.wordpress.com/2013/02/25/convert-sql-query-to-cakefind/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.