Query from another Table by id?


Hello dear community. Is there a possibility to display here right away a data from related column? Instead of Id on a second screenshot

Hey Bogdan welcome to the forum!

Assuming you have a different table where you have names for school_id's you can lookup those values and map them to the column.

Does this help?

Thank you for you prompt reply. Heey, at least i am going in the right direction!)
One thing left, how can i find out and use the variable of turrent table id to compare it with different table like you did? Take a look at my current screenshot please

Depending what is the name of your primary key in that table the code should look something like

{{formatDataAsArray(query4.data).filter(x=>x.school_id==item).map(x=>x.School_name)[0]}}

school_id just needs to be replaced with the actual key name.

Does that help?

2 Likes

Sorry. Even after many struggles, it still doesn't help. I tried to avoid using this table. But it is literally impossible.

Basically what i have - a table, where one column is just primary keys of other table.
I would love to fetch Names of schools instead of displaying just these numbers. Is that possible in retool?

I really want to show school name instead of school id. But names are in another tables by these ids

Hi @Bogdan_Mind I agree with Stefan's suggestion :thinking: Can you share a screenshot of what happens when you try that mapper?

Another option could be writing a single join query in MySQL :slightly_smiling_face:

1 Like

My whole life i thought i knew something about sql. But apparently nope). Meret1 | Editor | Retool - 27 July 2023 | Loom HEre is the screencast. I understand your possible frustration, maybe you can refer me to examples of such sort or documentation?

Found this topic. Table mapper -> value of another table - #3 by SIMTEC-Software-Solutions Got super puzzled. That is too complex for me. Do i assume it right, that there is no easier solutions for me?

After some time spent ABUSING gpt..


This query was born and task solved basically. I wouldn't say it was easy, but it was fun) Was there any easier solution?)

Eventually a fantastic advice about join query. Thank you very much!!

SELECT sch_table., stud_table. FROM
( SELECT * FROM students) AS stud_table JOIN schools AS sch_table
ON stud_table.school_id = sch_table.id

Gives all the stuff and i just cherry pich

1 Like

Hi @Bogdan_Mind Glad it's solved! :raised_hands: