SQL query without element repeated

0

I have this query in sql

SELECT 
    "Certificates"."Email", 
    "Organizations"."CommonName", 
    "Certificates"."Id", 
    "Certificates"."OrganizationId"
FROM
    "Certificates"
INNER JOIN 
    "Organizations" ON "Organizations"."Id" = "Certificates"."OrganizationId"
ORDER BY 
    "Email"
LIMIT 
     15
OFFSET 
     0

But it returns me all the certificates, there are certificates with repeated emails, I wish it were just single emails, I tried to use DISTINCT after SELECT, but it still returns the same thing

    
asked by anonymous 02.03.2018 / 17:28

1 answer

1

The behavior of your query is correct. It is likely that the Id of your table does not repeat, so it returns the data without collation even with Distinct .

For the results to return in a grouped form, use the query below.

SELECT     
    "Certificates"."Email", 
    "Organizations"."CommonName", 
     MAX("Certificates"."Id"), 
    "Certificates"."OrganizationId"
FROM
    "Certificates"
INNER JOIN 
    "Organizations" ON "Organizations"."Id" = "Certificates"."OrganizationId"
GROUP BY
   "Certificates"."Email", 
    "Organizations"."CommonName",
    "Certificates"."OrganizationId"
ORDER BY 
    "Email"
LIMIT 
     15
    
02.03.2018 / 17:39