0

How to make this work in Zend...

   select name, comment_id, text, date, number
from user, comment, telephone
where user.user_id = comment.user_id
and telephone.telephone_id = comment.telephone_id
and telephone.number = 000;

Thank you

Marcin
  • 173
  • 12

1 Answers1

1

I'm not sure about which column belongs to which table but it is quite simple to change it if I made a mistake. The query in Zend could be written like this :

$select = $db->select();
$select->from('user', array('name'));
$select->join('comment', 'user.user_id = comment.user_id', array('comment_id', 'text', 'date'));
$select->join('telephone', 'telephone.telephone_id = comment.telephone_id', array('number'));
$select->where('telephone.number = ?', '000');

I suggest you to read the documentation to be able to build select queries easily.

Fouad Fodail
  • 2,653
  • 1
  • 16
  • 16
  • Yes, this is correct, I check in documentation and it is works. Thank You. – Marcin Oct 21 '13 at 01:48
  • I got another question to you, there is possible to build this query on different way? – Marcin Oct 25 '13 at 05:12
  • @Marcin What a different way means? is [Zend_Db_Statement](http://framework.zend.com/manual/1.12/en/zend.db.statement.html) means a different way for you? Tell me more about what you need exactly. – Fouad Fodail Oct 26 '13 at 00:51
  • My Application is very slow and I think problem is with DB and I want to find the way to speed up DB. – Marcin Oct 26 '13 at 18:49