So i have to tables i would like to join but get an error.
The tables look like this.
patterns table:
patternUuid | urlName | title |
---|---|---|
1b3d8a0f-2bc3-4c50-a00a-6cf99335dd20 | card-fraud | Credit Card Fraud |
04bdcd7b-d61b-45cc-b9ea-c2decc77c852 | return-policy-fraud | Return Policy Fraud |
members table:
id | memberId | patternsUuid |
---|---|---|
1 | 1 | 1b3d8a0f-2bc3-4c50-a00a-6cf99335dd20 |
2 | 2 | 1b3d8a0f-2bc3-4c50-a00a-6cf99335dd20 |
3 | 3 | 04bdcd7b-d61b-45cc-b9ea-c2decc77c852 |
4 | 3 | 04bdcd7b-d61b-45cc-b9ea-c2decc77c852 |
my sql that gives me an error
SELECT "patternspatternUuid", "patterns.urlName", patterns.title, json_agg(members.memberId)
FROM public.patterns
JOIN members
ON members.patternsUuid = patterns.patternUuid
GROUP BY patterns.patternUuid
The error msg:
ERROR: column members.patternsuuid does not exist
LINE 4: ON members.patternsUuid = patterns.patternUuid
^
HINT: Perhaps you meant to reference the column "members.patternsUuid".
At the end I what to call this query and make it and endpoint and a res in json to look like this:
"patterns": [
{
"patternUuid": "1b3d8a0f-2bc3-4c50-a00a-6cf99335dd20",
"title": "Credit Card Fraud",
"urlName": "card-fraud"
"description": "Lorem ipsum dolor sit",
"members": [
{
"memberId": 1
},
{
"memberId": 2
}
],
},
2
Answers
So my query ended up like this and works now
Thanks for the answers as you can see, I had to use the quotes around the uppercase columns like this: members."memberId"
Probably your columns are declared using quoted identifiers, hence the proper name of column in
members
table ispatternsUuid
(declared as"patternsUuid"
) which is case sensitive. Identifiermembers.patternsUuid
is unquoted so it is equivalent topatternsuuid
which does not match real name.