AND,或在Codeigniter中使用In Join查询

时间:2018-06-26 04:38:16

标签: codeigniter join

如何在Codeigniter中使用下方查询

SELECT * FROM(post)JOIN user ON useruser_id = postuser_id JOIN friend ON (frienduser_id = postuser_id和friend.friendship_id = 1)或(friend.user_id = 1 ANDfriend.friendship_id = post.user_id)在哪里{{1 }}。post ='friend'ORDER BY type desc

2 个答案:

答案 0 :(得分:0)

您可以使用它。

$this->db->query(your query);

喜欢此代码。

$sql = "SELECT * FROM table WHERE user_id = 1";
$this->db->query($sql);

答案 1 :(得分:0)

尝试

$query = $this->db
    ->select('*')
    ->from('post')
    ->join('user', 'user.user_id = post.user_id')
    ->join('friend', 'friend.user_id = (post.user_id AND friend.friendship_id=1) OR (friend.user_id = 1 AND friend.friendship_id = post.user_id)')
    ->where('post.type', 'friend')
    ->order_by('postid','DESC')
    ->get();

$arrResult = $query->result();