1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Why INNER JOIN self while you can do without?

Discussão em 'Outras Linguagens' iniciado por Stack, Maio 17, 2021.

  1. Stack

    Stack Membro Participativo

    $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...

Compartilhe esta Página