Problem regarding returning the query in the requird shape

Hello guys,
i am trying to execute the below query and for one product i want to get all the products which lies in the similar category and price range but if i want to store all resultant product against the only product for which i queried(basically one product and against that all resultant products in one row itself, not in individual row each time)
how can i do it ?

"match(p1:Product) with COLLECT({ProductId: p1.ProductId }) as ws
unwind ws as ws1
match(pr:Product{ProductId : ws1.ProductId})<-[:HasProduct]-(c:Category)
match(c)-[:HasProduct]->(p:Product)
where p.Price>0.5pr.Price and p.Price<2pr.Price
return pr.ProductId, p.ProductId"

thanks

Hey @shubham, use collect procedure at the end may solve your problem

"match(p1:Product) with COLLECT({ProductId: p1.ProductId }) as ws
unwind ws as ws1
match(pr:Product{ProductId : ws1.ProductId})<-[:HasProduct]-(c:Category)
match(c)-[:HasProduct]->(p:Product)
where p.Price>0.5 pr.Price and p.Price<2 pr.Price
with pr, collect(p.ProductId) as products
return pr.ProductId, products"

1 Like