I'm stucked in this problem and searching a solution for 2 hours.
In fact I have a posts table which contains all comments in my app.
Each post data has a row called ownerid which keeps the id of the owner of this comment.
And it also contains a row called groupid.
What I want to have is to select all posts with a certain groupid (eg. 2).
and the motto from the user which is in users table.
So something like this.
SELECT * FROM posts WHERE groupid = 2
SELECT motto FROM users WHERE userid = $row['ownerid']
$stmt->bind_result($postid, $motto, $groupid, $text, $postdate);
If I undestand correctly your question, you should try
SELECT P.*, U.motto from posts P INNER JOIN users U on P.ownerid = U.userid WHERE P.groupid = 2;