I am very familiar with MySQL syntax but am seemingly running into some growing pains moving into a PostgreSQL environment. In MySQL you can reference columns in joined subqueries easily but I am thrown errors in PostgreSQL.
For example:
SELECT
a.userID,
b.firstname,
c.minCounter
FROM users a
JOIN users_info b ON (a.userID = b.userID)
LEFT JOIN (
SELECT
user_id,
COUNT(*) AS 'minCounter'
FROM sales
WHERE
total_amount > 500
GROUP BY user_id
) as c ON (b.userID = c.user_id)
referencing the subquery "c" and its temp column "minCounter" has no issues. In PostgreSQL however, a similar query would return the error:
ERROR: syntax error at or near "'minCounter'"
LINE 10: COUNT(*) AS 'minCounter'
Accounting for literal versus named columns
If I switch Line 10 to state: COUNT(*) AS "minCounter"
my error simply adjusts to:
ERROR: column c.mincounter does not exist
LINE 4: c.minCounter
Any suggestions as to what syntax or general naming difference there are that I'm missing?
(Note, I am not sure what version of PostgreSQL we are running because it is obfuscated by our external dev team).
Thanks!