Hi everyone,
I’ve checked a lot of threads here but I’m still stuck with something: Getting the name instead of the ID of a second table with a Join.
I have these two tables:
- Posts (rows: ID, Title, Category) - The Category row is the Reference for the ID from the Categories table
- Categories (ID, Title) - The
In my page, with the repeat component, I try to show all the posts from my DB and just after the Post Title I would like to show the Category Title associated.
It’s currently showing the Category ID and not the Category Title.
It seems that I need to use the Inner Join (or Left or Right) in order to achieve this, but I can’t get it work unfortunately.
I’ve checked a lot of posts, even those:
Every time I try the solutions I get this message:
{status: "500", code: "ER_DUP_FIELDNAME",…}
code: "ER_DUP_FIELDNAME"
message: "select count(*) as `Total` from (select `Posts`.`id`, `Posts`.`category`, `Posts`.`title`, `Posts`.`description`, `Posts`.`tag`, `Posts`.`slug`, `Posts`.`public`, `Posts`.`creation_date`, `cat`.`id`, `cat`.`title`, `cat`.`description`, `cat`.`slug` from `Posts` left join `Categories` as `cat` on `cat`.`title` = `Posts`.`category` where `Posts`.`public` = true order by `Posts`.`id` DESC) as `t1` limit 1 - ER_DUP_FIELDNAME: Duplicate column name 'id'"
stack: "Error: ER_DUP_FIELDNAME: Duplicate column name 'id'↵ at Query.Sequence._packetToError (/opt/node_app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)↵ at Query.ErrorPacket (/opt/node_app/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)↵ at Protocol._parsePacket (/opt/node_app/node_modules/mysql/lib/protocol/Protocol.js:291:23)↵ at Parser._parsePacket (/opt/node_app/node_modules/mysql/lib/protocol/Parser.js:433:10)↵ at Parser.write (/opt/node_app/node_modules/mysql/lib/protocol/Parser.js:43:10)↵ at Protocol.write (/opt/node_app/node_modules/mysql/lib/protocol/Protocol.js:38:16)↵ at Socket.<anonymous> (/opt/node_app/node_modules/mysql/lib/Connection.js:88:28)↵ at Socket.<anonymous> (/opt/node_app/node_modules/mysql/lib/Connection.js:526:10)↵ at Socket.emit (events.js:315:20)↵ at addChunk (_stream_readable.js:295:12)↵ --------------------↵ at Protocol._enqueue (/opt/node_app/node_modules/mysql/lib/protocol/Protocol.js:144:48)↵ at Connection.query (/opt/node_app/node_modules/mysql/lib/Connection.js:198:25)↵ at /opt/node_app/node_modules/knex/lib/dialects/mysql/index.js:135:18↵ at new Promise (<anonymous>)↵ at Client_MySQL._query (/opt/node_app/node_modules/knex/lib/dialects/mysql/index.js:129:12)↵ at Client_MySQL.query (/opt/node_app/node_modules/knex/lib/client.js:169:17)↵ at Runner.query (/opt/node_app/node_modules/knex/lib/runner.js:151:36)↵ at /opt/node_app/node_modules/knex/lib/runner.js:40:23↵ at /opt/node_app/node_modules/knex/lib/runner.js:277:24↵ at processTicksAndRejections (internal/process/task_queues.js:97:5)"
status: "500"
This error message is pretty clear: Duplicate column name ‘id’
BUT I don’t know how I could fix it, I can’t rename the ID in my Database structure with Wappler.
I just would like to be able to select the category name and show it in my content page for every post (it’s a list of posts).
Does anyone know how I could do this?
Last updated: