$query[] = 'SELECT DISTINCT c.*,'; if ($behavior == 'category' && $categoryId) { $query[] = '0 as `featured`'; $query[] = 'FROM ' . $db->quoteName('#__easyblog_category') . ' AS a'; $query[] = 'INNER JOIN ' . $db->quoteName('#__easyblog_category') . ' AS a1'; $query[] = 'ON a.' . $db->quoteName('id') . ' = a1.' . $db->quoteName('id') . ' AND a1.' . $db->quoteName('id') . ' = ' . $db->Quote($categoryId); $query[] = 'INNER JOIN ' . $db->quoteName('#__easyblog_post') . ' AS c'; $query[] = 'ON a1.' . $db->quoteName('id') . ' = c.' . $db->quoteName('category_id'); $query[] = 'WHERE c.' . $db->quoteName('id') . '!=' . $db->Quote($id); } I am trying to understand the code above, which is part of a query building function. It is used to find related posts of a certain post by select all posts in the post's category except the post itself. I don't understand why the code above inner joins the category table itself. Shouldn't this be working already? $query[] = 'SELECT DISTINCT c.*,'; if ($behavior == 'category' && $categoryId) { //change $query[] = '0 as `featured`'; $query[] = 'FROM ' . $db->quoteName('#__easyblog_category') . ' AS a'; $query[] = 'INNER JOIN ' . $db->quoteName('#__easyblog_post') . ' AS c'; $query[] = 'ON a.' . $db->quoteName('id') . ' = c.' . $db->quoteName('category_id'); $query[] = 'WHERE c.' . $db->quoteName('id') . '!=' . $db->Quote($id); } Continue reading...