Search code examples
postgresqlcountsubquerysql-order-byinner-join

Inner Join subquery in Postgresql results in error


There is my request to find actualities on my website, I got error in this request and I don't know what i need to do for solve this error

Error:

Column "quote_plus_normal_gr_publi.id_post_normal" must appear in the GROUP BY clause or be used in an aggregate fun

Query:

SELECT 
    publi.date, publi.mess, publi, publi.profil, publi.color, 
    publi.name, publi.search
FROM 
    publi
INNER JOIN 
    (SELECT 
         id_post_normal, COUNT(id_post_normal)
     FROM 
         quote_plus_normal_gr_publi
     ORDER BY 
         id_post_normal) q ON q.id_post_normal = publi.id_post_normal
WHERE 
    publi.id_personnes = 1
ORDER BY 
    date DESC

Solution

  • I think something wrong in your select statement

    SELECT publi.date, publi.mess, publi, publi.profil, publi.color, publi.name, publi.search
    
    FROM publi
    INNER JOIN (
        SELECT id_post_normal, COUNT(id_post_normal)
        FROM quote_plus_normal_gr_publi
        ORDER BY id_post_normal
    ) q 
    ON q.id_post_normal = publi.id_post_normal
    WHERE publi.id_personnes = 1
    ORDER BY date DESC
    

    in first select there are just publi and don't have column to call

    select publi.date, publi.mess, publi, publi.profil
    

    so i try query and make similar to you and i don't have any error to show.

    first why the error show up group by? do you try another query? not this query?