[英]Mysql - How to select entries from one table based on whether or not I subscribe to them from another table?
對於我的生活,我無法解決這個簡單的mysql問題。 (我的大腦是油炸的,差不多16個小時的直接編碼)。
基本上,我有表條目和訂閱
項
訂閱
我希望能夠選擇由所有我在訂閱訂閱人發布的所有條目。
我很樂意,如果有可能用codeigniter的activerecord語法來做這件事,但如果不可能,那么普通的mysql語法將會非常受歡迎。
我在這里錯過了什么概念? 它是一個簡單的連接還是循環通過我訂閱的所有人並查找由他們發布的條目?
非常感謝。
你可以使用JOIN。 在純SQL中:
SELECT e.publisherId, e.entry
FROM entries e
JOIN subscriptions s
ON s.friendId = e.publisherId
WHERE s.myId = 1234
讓我知道它是否有效,因為我還在學習Active Query記錄(加入對我來說很困惑:P)
$this->db->select('entries.publisherId,entries.entry');
$this->db->from('entries');
$this->db->join('comments', 'subscriptions.friendId = entries.publisherId');
$this->db->where('subscriptions.myId', 1234);
$query = $this->db->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.