 <p>I think I found an easier way:</p> <pre><code>CREATE VIEW indexed_posts AS SELECT * FROM posts, users WHERE post_author = user_id WITH CHECK OPTION; </code></pre> <p>Then I can use query:</p> <pre><code>SELECT * FROM indexed_posts WHERE user_id = $_SESSION['user_id']; </code></pre>