1

I'm supposed to run this query in PGadmin:

SELECT
    n2.cpr, 
    n2.adresseringsnavn,
    n2."fødselsdato" AS foedselsdato, 
    n2.morcpr,
    n1.mor_navn,
    n2.farcpr,
    n3.far_navn
FROM 
    (SELECT * FROM data.cpr_aktivkom_geoview WHERE
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x' OR
        cpr = 'x') n2
INNER JOIN
    (SELECT cpr, adresseringsnavn AS mor_navn
    FROM data.cpr_aktivkom_geoview) n1
ON n2.morcpr = n1.cpr
LEFT JOIN
    (SELECT cpr, adresseringsnavn AS far_navn
    FROM data.cpr_aktivkom_geoview) n3
ON n2.farcpr = n3.cpr
ORDER BY n2."fødselsdato" asc
ERROR:  syntax error at or near "."
LINE 2:     n2.cpr, 
              ^ 

SQL state: 42601
Character: 14

What is the problem with the dot after the n2's, n1's and n3's?

4
  • Nothing obvious except for the duplicate WHERE clauses. Are you executing exactly this, or along with other queries? Commented Nov 17, 2023 at 11:55
  • What happens if you run just the inner query of the n2 alias (the query against data.cpr_aktivkom_geoview)? Agreed with Charlieface too, are you running exactly this query or did you change it and / or are running other queries with it?...it's odd that the inner query of n2 has the same OR clause repeated 11 times.
    – J.D.
    Commented Nov 17, 2023 at 13:33
  • Check for invisible nonstandard characters in your copypaste, like unbreakable space etc. A good way to do this is to paste in a text editor.
    – bobflux
    Commented Nov 18, 2023 at 23:00
  • Very likely, you are making a mistake using pgAdmin: make sure that only your statement is in the query window. My guess is that you have some text before the statement in the window. Commented Nov 20, 2023 at 7:12

1 Answer 1

1

If I remember correctly, it’s because the SELECT is on its own line. Try this.

SELECT n2.cpr,
       n2.addresseringsnavn,
. . .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.