title: SQL - Return books that user owns
body: <p>I'm doing I'm having a bit of a problem performing a query in my university project. I got a website where users share the books that they've read and I have a page where the user can view the books he has added (the books he owns).</p>
  
  <p>For that I believe I need the logged user's id, which I store in a session PHP variable, the user id is in table users.
  The information about the books is stored in a table books and it has its own id primary key.
  Then, to show who owns what I have a table owns_book (id, u_id, book_id).</p>
  
  <p>Right now for testing I've got 26 books total, 25 of them are added by a user with id of 57 and 1 book by user with id of 49.
  When I run this query:</p>
  
  <pre><code>SELECT id, title, author, category, cover, added, user_id FROM books, users 
  WHERE user_id=49 AND id IN(SELECT book_id FROM owns_book) 
  AND user_id IN(SELECT u_id FROM owns_book)
  </code></pre>
  
  <p>And the result is a mess, I don't get the expected one book, I also get books added by the other user.
  Can someone please show me the correct query that I need or if I need to change the structure of my tables? Thanks.</p>
  
  <p>EDIT:</p>
  
  <pre><code>users(user_id, ...) 
  books(id, title, author, publisher, published, cover... ) 
  owns_book(id, u_id, book_id)
  </code></pre>