Populating a field in one table with text value from another table
So to preface this, I'm not really a "database guy" per se, I'm much more of a spreadsheet guy, and it's been a while since I've built a db. I'm mostly relying on my scripting experience in other scenarios (batch and BASH basically, and I can stumble my way through reading a JS query), but so far this has been failing me.
Excuses out of the way, I'm working on a database for a trading card collection. It has two tables, which we'll refer to as T1 and T2. T1 is the "main" table that lists all of the cards, and T2 is a ban list. What I'm trying to do is set up a field in T1 that will compare T1.Name to T2.Name and when a match is found, show the value from T2.LVLban, otherwise it should show as "Unlimited". I had this set up in Excel using the XLOOKUP function and it did what I wanted it to, but the list is over 10k records, so Excel wasn't really able to cope with the load.
So far I have tried various permutations of the following formulas, with the goal of populating the field T1.LVLban:
if T1.Name = T2.Name then T2.LVLban else "Unlimited"
and
if T1.Name = T2.Name and T2.LVLban = "Forbidden" then "Forbidden"
else if T1.Name = T2.Name and T2.LVLban = "Limited" then "Limited"
else if T1.Name = T2.Name and T2.LVLban = "Semi-Limited" then "Semi-Limited"
else "Unlimited"
I've tried these in both a formula field and in a table reference field with no luck so far. I feel like the logic itself should work (or that it at least makes sense), I'm just not confident in where it needs to be entered. I've been searching through the docs and so far everything I've come across hasn't actually gotten me where I'm trying to go, so any guidance or suggestions you could provide would be greatly appreciated.
5 replies
-
Hi Stephen
You could make a quick fix by finding T1 Name in T2 Name and returning the LVLban value in a formula field called LVLban in T1
let a := Name;
first(select T2 where Name = a).LVLbanIt might be a more permanent solution to create a 1 to many realtionship between T2 and T1 and showing T2.LVLban in T1
Regards
John
-
Hi Stephen -
Your thinking would working if there is a relationship between T1 and T2. If there is no reference field in either table linking the two then you just can't say:
as Ninox has no way of knowing what T1 or T2 is.
That is why you see the select statement in John's comments.
It took me a while to figure out how to use relationships to my advantage and had to redesign my db along the way to make it smarter. Here is a link to a horde of videos around Ninox: https://www.youtube.com/c/NinoxLearning/videos
Good Luck.
-
Thank you both! John's code got me like 95% of the way where I'm wanting to go. Still can't figure out the default value if no match is found, but that's honestly a low priority.
-
let a := Name;
let b := first(select T2 where Name = a).LVLban;
if b = null then "Not Found" else b end -
My new favorite person! You hit it right on the head, and have my gratitude.
Content aside
- 3 yrs agoLast active
- 5Replies
- 637Views