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

chchrist
  • 18,854
  • 11
  • 48
  • 82

3 Answers3

0

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

Hardik Sondagar
  • 4,347
  • 3
  • 28
  • 48
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

diagonalbatman
  • 17,340
  • 3
  • 31
  • 31
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. :-)

Rob Wilkerson
  • 40,476
  • 42
  • 137
  • 192