1

我有以下sql语句

SELECT a.* FROM accounts a 
JOIN account_friends f 
ON f.friend_id = a.id 
WHERE f.account_id = 12;

这会导致类似

id    username    password    email
14      test        test       ..
15      test2       test       ..

我不能做的就是将其转换为 zend 语句。我试过这个

    $accFriendTable = new Default_Model_DbTable_AccountFriends();
    $query = $accFriendTable->select()->setIntegrityCheck(false);
    $query->from(array('a' => 'accounts'), array('a.*'));
    $query->join(array('f' => 'account_friends'), 'f.friend_id = a.id');
    $query->where('f.account_id = ?', $this->_id);
    $friendsList = $accFriendTable->fetchAll($query);

这导致从 accounts 表和 account_friends 表中选择这两个列,就像这样

id    username    password    email    account_id    friend_id
1      test        test        ..         12             14
2      test2       test        ..         12             15

任何帮助,将不胜感激 :)

4

1 回答 1

0

您需要从连接表中提供所需的列数组,因为默认情况下它将从它们中获取所有列。

如果您不希望任何列NULL像下面一样通过,

$query->join(array('f' => 'account_friends'), 'f.friend_id = a.id',NULL);
于 2013-03-01T13:49:50.720 回答