# Two collection in same data query on basis of reference key

**URL:** <https://forum.wixstudio.com/t/two-collection-in-same-data-query-on-basis-of-reference-key/8874>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [July 13, 2018, 2:14pm UTC](https://forum.wixstudio.com/t/two-collection-in-same-data-query-on-basis-of-reference-key/8874 "2018-07-13T14:14:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![awaisjamil88](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@awaisjamil88](https://forum.wixstudio.com/u/awaisjamil88)\
**Post date:** [July 13, 2018, 2:14pm UTC](https://forum.wixstudio.com/t/two-collection-in-same-data-query-on-basis-of-reference-key/8874/1 "2018-07-13T14:14:36Z")

</div>

Hi, I want to ask a question related to wix code. How can we combine two collection of database while writing a wix data query? Like for example there is a query

import wixData from ‘wix-data’;  
wixData.query(“Customer”)  
.gt(“age”, 20)  
.ascending(“name”)  
.limit(15)  
.find()  
.then( (results) =\>  
{ console.log(results.items); } );

I want another collection in the same query which has a reference field in the Customer Collection. Basically I want to get combined data from both collection. Like we combine two tables in sql database on the basic on foreign key. I want to apply same idea here too. I will be very thankful, please guide me.  
Thanks  
Awais

---

<div class="post-metadata">

**Author:** ![breut75](https://avatars.discourse-cdn.com/v4/letter/b/58956e/32.png) [@breut75](https://forum.wixstudio.com/u/breut75)\
**Post date:** [July 15, 2018, 5:50am UTC](https://forum.wixstudio.com/t/two-collection-in-same-data-query-on-basis-of-reference-key/8874/2 "2018-07-15T05:50:27Z")

</div>

I’m looking for the exact same thing - query joined collections (joined on reference field).

Datacollections allow you to access any field from the linked tables, but wix data query does not seem to support this from what I can tell.

Worst case scenario is going to be finding all the distinct values of your reference field in customer table, and then querying the reference table separately. That would be ridiculously inefficient though.

---

<div class="post-metadata">

**Author:** ![breut75](https://avatars.discourse-cdn.com/v4/letter/b/58956e/32.png) [@breut75](https://forum.wixstudio.com/u/breut75)\
**Post date:** [July 15, 2018, 6:24am UTC](https://forum.wixstudio.com/t/two-collection-in-same-data-query-on-basis-of-reference-key/8874/3 "2018-07-15T06:24:00Z")

</div>

Actually there is a way to include the referenced collection: [http://www.wix.com/code/reference/wix-data.WixDataQuery.html#include](http://www.wix.com/code/reference/wix-data.WixDataQuery.html#include) . Just got it to work. Not thrilled about how the data from the referenced collection is nested as it is, but at least you can access it.

---

<div class="post-metadata">

**Author:** ![awaisjamil88](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@awaisjamil88](https://forum.wixstudio.com/u/awaisjamil88)\
**Post date:** [July 15, 2018, 8:39am UTC](https://forum.wixstudio.com/t/two-collection-in-same-data-query-on-basis-of-reference-key/8874/4 "2018-07-15T08:39:41Z")

</div>

Thanks a lot Peter. I think this will work.

---

<div class="post-metadata">

**Author:** ![squeezeoj](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@squeezeoj](https://forum.wixstudio.com/u/squeezeoj)\
**Post date:** [August 18, 2021, 2:02am UTC](https://forum.wixstudio.com/t/two-collection-in-same-data-query-on-basis-of-reference-key/8874/5 "2021-08-18T02:02:18Z")

</div>

This link now returns 404 Not Found. Any idea what happened to it?
