如何在Codeigniter中使用下方查询
SELECT * FROM(post
)JOIN user
ON user
。user_id
= post
。user_id
JOIN friend
ON (friend
。user_id
= post
。user_id
和friend.friendship_id = 1)或(friend.user_id = 1 ANDfriend.friendship_id = post.user_id)在哪里{{1 }}。post
='friend'ORDER BY type
desc
答案 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();