Help in writing the right query?!

it might be easy , or even newbie thing. but i am new to all of this, and i’d really appreciate if you help me.

I have wix store, in product page i created an “related items” area :


now my question is : I have created Database named RelatedItem , the purpose of this DB is :
for each product, there’s 3 columns : Relatedone, RelatedTwo , RelatedThree.
That means, for each product, it has three related products ID
See image below:


now what i am trying to do , is: when I enter a product page, I get the Product it.
Im trying to query the RelatedItem to find the productID im standing on right now, and get the three related items IDs in variables. I know sql but i do not know right it in wix!
something like:
SELECT relatedOne,relatedTwo,relatedThree
FROM relatedItem
WHERE (ID of product in the page im on rightnow) == productId

I wanted something like that:
search for the productId in RelatedItem DB
Once you find it do:
Var Item1 = relatedOne
Var Item2 = relatedTwo
Var Item3 = relatedThree

Thats it for now, I am failing to walk through this step. can anyone please help me?! Thank you!

anyone? please i really need help!

itl only idea. Check field names, upper letters,etc Use console.log to check
wixData.query(“Relateditem”)
.eq(“productid”, product id from page)
.find()
.then((res)=>{
let item = res.items[0]
Var Item1 = item.relatedOne
Var Item2 = item.relatedTwo
Var Item3 = item.relatedThree
)}

I am just trying on ready to run the query (just for trying, to make the query look for productId = “B” Which it does exist, but with no luck , still getting undefined!

could you please look what am i doing wrong here??
you can see the DB in the picture above!

$w.onReady( function () {

wixData.query(“RelatedItem”)
.eq(“productId”, “B”)
.find()
.then( (results) => {
let items = results.items;
let firstItem = items[0];
let totalCount = results.totalCount;
let pageSize = results.pageSize;
let currentPage = results.currentPage;
let totalPages = results.totalPages;
let hasNext = results.hasNext();
let hasPrev = results.hasPrev();
let length = results.length;
let query = results.query;
console.log(firstItem);
} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );

});

I am just trying on ready to run the query (just for trying, to make the query look for productId = “B” Which it does exist, but with no luck , still getting undefined! could you please look what am i doing wrong here??
you can see the DB in the picture above!

$w.onReady( function () {

wixData.query(“RelatedItem”)
.eq(“productId”, “B”)
.find()
.then( (results) => {
let items = results.items;
let firstItem = items[0];
let totalCount = results.totalCount;
let pageSize = results.pageSize;
let currentPage = results.currentPage;
let totalPages = results.totalPages;
let hasNext = results.hasNext();
let hasPrev = results.hasPrev();
let length = results.length;
let query = results.query;
console.log(firstItem);
} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );

});
});

i alwey do like this
write console.log(firstItem) and see is shows anything
than console.log(items)
if so it means there is misstake in name collection or query. What is “B”. On picture product is is _id so its long strong sa for sure its not B. In Query .eq means find product that has id =123456789 the equal to field product id. So B equal to B

Done! thanks to you!
Thank you verymuch! for responding and for your help.

please mark top comment if it helped :slight_smile: