I’m trying to do a join between tables 1 and 2 which have a 1 to many relationship.
table1 has the following fields
- createdate
- contact
- tkey (surrogate key)
table2 has the following fields
- tkey (primary key)
- status
- userfld1
- description
I want to show all items in table2 with their corresponding items in table1 grouped by table2.userfld1
select distinct t2.userfld1, t2.status, t2.description, t1.createdate, t1.contact
from table2 as t2 left join table1 as t1
on t2.tkey = t1.tkey
group by t2.userfld1
is this correct?
No that’s not correct, you can’t select columns that aren’t in the group by unless they are contained in an aggregate function. And I think what you are asking for doesn’t even make sense. My best guess is that you mean ORDER BY, not GROUP BY:
Three other errors that I’ve fixed: