Sub tables with joins

Sub tables is a great new feature guys.

I’m using sub tables having not been created in Wappler.

I’m doing a query of
contacts left join companies

Both of these tables present in the UI with a sub table of phones, presumably because of foreign keys (?)

The phones that are returned are coming from the companies.

Is there a way to instead/also get the phones for contacts?

In the example above, the contact with ID 3 should also have a phone.

Do you have a nested join on the “phones” column?

You can double click on it in the columns grid to call a nested query builder dialog where you can specify the options for the nested query.

I didn’t in the above example.

So here is a new test:

Results in:

code: "ER_NON_UNIQ_ERROR"
message: "select * from `phones` where `company_id` in (select `contact_id` from `contacts` as `contacts` left join `companies` on `companies`.`company_id` = `contacts`.`company_id` left join `phones` as `contact_phones` on `contact_phones`.`contact_id` = `contacts`.`contact_id`) - ER_NON_UNIQ_ERROR: Column 'contact_id' in field list is ambiguous"
stack: "Error: ER_NON_UNIQ_ERROR: Column 'contact_id' in field list is ambiguous\n    at Query.Sequence._packetToError (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)\n    at Query.ErrorPacket (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)\n    at Protocol._parsePacket (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/protocol/Protocol.js:291:23)\n    at Parser._parsePacket (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/protocol/Parser.js:433:10)\n    at Parser.write (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/protocol/Parser.js:43:10)\n    at Protocol.write (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/protocol/Protocol.js:38:16)\n    at Socket.<anonymous> (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/Connection.js:88:28)\n    at Socket.<anonymous> (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/Connection.js:526:10)\n    at Socket.emit (events.js:315:20)\n    at addChunk (internal/streams/readable.js:309:12)\n    --------------------\n    at Protocol._enqueue (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/protocol/Protocol.js:144:48)\n    at Connection.query (/Users/pauka/WapplerProjects/cf/node_modules/mysql/lib/Connection.js:198:25)\n    at /Users/pauka/WapplerProjects/cf/node_modules/knex/lib/dialects/mysql/index.js:132:18\n    at new Promise (<anonymous>)\n    at Client_MySQL._query (/Users/pauka/WapplerProjects/cf/node_modules/knex/lib/dialects/mysql/index.js:126:12)\n    at executeQuery (/Users/pauka/WapplerProjects/cf/node_modules/knex/lib/execution/internal/query-executioner.js:37:17)\n    at Client_MySQL.query (/Users/pauka/WapplerProjects/cf/node_modules/knex/lib/client.js:144:12)\n    at Runner.query (/Users/pauka/WapplerProjects/cf/node_modules/knex/lib/execution/runner.js:130:36)\n    at ensureConnectionCallback (/Users/pauka/WapplerProjects/cf/node_modules/knex/lib/execution/internal/ensure-connection-callback.js:13:17)\n    at Runner.ensureConnection (/Users/pauka/WapplerProjects/cf/node_modules/knex/lib/execution/runner.js:272:20)"
status: "500"

If I double click to create a sub query, how would I specify the parent contact_id?

It does this automatically based on the table relations.

For the other error @patrick will check it out, but we already have many improvements ready for the update for tomorrow so it will be probably solved.

1 Like

You may test the latest update which will be released today, I think it probably will fix your error.

dbconnector.zip (1.8 KB) Unzip to lib/modules.

Thanks Patrick…this works, but actually the older version also works. But to make either work, I had to recreate the query from scratch, so I’m thinking something was wrong in the editor rather than the query processing itself.

Fixed in Wappler 4.7.1

This topic was automatically closed after 46 hours. New replies are no longer allowed.