I have been a long time reader of site but havenever posted before and am hoping someone here can help. I am working on a multi-user web application which allows users to capture prospect information into our database. The users will be given default fields inside the app, such as name and email which are grouped into data groups.

However i want to allow the users to create as many custom fields as they wish and also allow them to choose which data group these custom fields belong in group. I am struggling to figure out the best way to achieve this.

I have currently have 3 tables in my data which are as follows:

```
datagroups

group_id   group_name    order
1          test group 1    2
2          test group 2    1

datafields

field_id      field_name    group
   1           field 1        2
   2           field 2        1
   3           field 3        2

customdatafields

custom_field_id     field_name      group
      1               custom 1       1
      2               custom 2       2

```

I am really puzzled on how I would create a query across the 3 tables so that I can produce a view following display:

```
test group 2
- field 1
- field 3
- custom 2

test group 1
- field 2
- custom 1

```

One thing I need to keep in mind is that I may allow the users to create custom data groups also that that needs to be factored into this.

Any input on this would be much appreciated.

Thanks