# Need Assistance with Dgraph Query Filtering Issue

**URL:** https://discuss.dgraph.io/t/need-assistance-with-dgraph-query-filtering-issue/18983
**Category:** Dgraph
**Created:** [October 11, 2023, 8:55am UTC](https://discuss.dgraph.io/t/need-assistance-with-dgraph-query-filtering-issue/18983 "2023-10-11T08:55:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JY-Sun-K](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jy-sun-k/32/10368_2.png) [@JY-Sun-K](https://discuss.dgraph.io/u/JY-Sun-K)
#### Post date: [October 11, 2023, 8:55am UTC](https://discuss.dgraph.io/t/need-assistance-with-dgraph-query-filtering-issue/18983/1 "2023-10-11T08:55:13Z")

</div>

## What I want to do

I want to execute a Dgraph query to fetch data from a specific block (let’s call it “l”) while applying filters, and then further filter the results from this “l” block and return only the data that matches the secondary filter conditions. I want to ensure that the data block of the query contains only data from the “l” block.

## What I did

_ **query:** _

> query Instances($page: int, $offset: int, $state: string) {  
> l(func: type(“DataInstance”), first: $page, offset: $offset) @filter(regexp(state, /^saved/)) @cascade {  
> v as uid  
> instancetable @filter(regexp(name, /(._2._)/i)) {  
> name  
> }  
> state  
> }  
> data(func: uid(v)) @recurse(loop: false) {  
> uid  
> instancetable  
> name  
> state  
> }  
> }

_ **result:** _

> “data”: {  
> “l”: [  
> {  
> “uid”: “0x42158e”,  
> “instancetable”: {  
> “name”: “234”  
> },  
> “state”: “saved\_table\_deployed”  
> }  
> ],  
> “data”: [  
> {  
> “uid”: “0x42158e”,  
> “instancetable”: {  
> “uid”: “0x42157c”,  
> “name”: “234”,  
> “state”: “”  
> },  
> “state”: “saved\_table\_deployed”  
> },  
> {  
> “uid”: “0x4261cd”,  
> “instancetable”: {  
> “uid”: “0x3cdc65”,  
> “name”: “WaterproofingAndDrainageAccessory”,  
> “state”: “”  
> },  
> “state”: “saved\_table\_deployed”  
> },  
> {  
> “uid”: “0x4261d2”,  
> “instancetable”: {  
> “uid”: “0x3cdd8f”,  
> “name”: “WingWall”,  
> “state”: “”  
> },  
> “state”: “saved\_table\_deployed”  
> }  
> ]  
> }

## Dgraph metadata

> **dgraph version**
>
> _v20.07.2_

---

<div class="post-metadata">

### Author: ![Raphael](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/raphael/32/10075_2.png) [@Raphael](https://discuss.dgraph.io/u/Raphael)
#### Post date: [October 12, 2023, 1:35am UTC](https://discuss.dgraph.io/t/need-assistance-with-dgraph-query-filtering-issue/18983/2 "2023-10-12T01:35:21Z")

</div>

> [@JY-Sun-K](#):
>
> l(func: type(“DataInstance”), first: $page, offset: $offset) @filter(regexp(state, /^saved/)) @cascade {  
> v as uid

could you change that to

```auto
v as var(func: type(“DataInstance”), first: $page, offset: $offset) @filter(regexp(state, /^saved/)) @cascade {
--- delete the line v as uid

```

and let me know. It is the correct way to build the variable based on your “I” query.

---

<div class="post-metadata">

### Author: ![JY-Sun-K](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jy-sun-k/32/10368_2.png) [@JY-Sun-K](https://discuss.dgraph.io/u/JY-Sun-K)
#### Post date: [October 12, 2023, 6:09am UTC](https://discuss.dgraph.io/t/need-assistance-with-dgraph-query-filtering-issue/18983/3 "2023-10-12T06:09:06Z")

</div>

Thank you very much for your response, it resolved my issue.

However, I tried the query method I described on “[https://dgraph.io/docs/query-language/query-variables/,](https://dgraph.io/docs/query-language/query-variables/,)”  
and it seems to give me the expected results. Can you tell me the difference between the two,

> v as var(func:…)

and

> var(func:…){ v as uid }

?  
thank you
