chriscloyd Posted May 12, 2013 Share Posted May 12, 2013 I have two results could $result = mysql_query("select CommentID, CommentName, CommentLikes, CommentAuthor, CommentDate from Comments where BlogID = '{$blogID}' and SubComment = '0' and Access >= '{$User->info['Access']}' order by {$sort} limit {$limit}"); $result2 = mysql_query("select CommentID, CommentName, CommentLikes, CommentAuthor, CommentDate from Comments where SubComment = '{$cline['CommentID']}' and Access >= '{$User->info['Access']}'"); can i inner join to get the sub comments right after the main comments, even though they are in the same table? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 Try, $sql = "select CommentID, CommentName, CommentLikes, CommentAuthor, CommentDate from Comments where BlogID = '{$blogID}' AND CommentID IN ( select CommentID from Comments where SubComment = '{$cline['CommentID']}' and Access >= '{$User->info['Access']}')"; Quote Link to comment Share on other sites More sharing options...
Barand Posted May 12, 2013 Share Posted May 12, 2013 You can join a table to itself by using table aliases EG SELECT cat.name, sub.name FROM category cat INNER JOIN category sub ON cat.id = sub.parent_id Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.