Thinking in sub tables

Sorry, late to the show (again) but think this is important

Sub tables and joins work differently and therefore their output is not the same so in some cases joins are appropriate, others sub tables

So if i take a simple users table (this is from the sample data in docker) and I add to it a sub table of role

image

Now to illustrate the difference i now add a separate role table

image

Both role tables have the same content, two roles “A” and “E” attached to user id = 1

I then create two queries, one using a join, the other via sub tables

image

the query named join uses an inner

The query called sub table uses a sub table

So identical data will give the same result? NO

Running the query and examining the output we see

Note the join returns two full rows with the data effectively merged.

The sub table query returned nested data, one record for the id and a nested list for the roles

I suspect this results from Wappler using nested queries to manage sub tables and this does not return the same as a join

So when deciding to use nested tables or joins you must consider how you will use the data and in which form best suits your specific needs

Hope this helps

5 Likes