# Filter on comparison between fields

**URL:** <https://community.weweb.io/t/filter-on-comparison-between-fields/7693>\
**Category:** How do I?\
**Tags:** filter, supabase\
**Created:** [March 21, 2024, 1:42pm UTC](https://community.weweb.io/t/filter-on-comparison-between-fields/7693 "2024-03-21T13:42:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Larry](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@Larry](https://community.weweb.io/u/Larry)\
**Post date:** [March 21, 2024, 1:42pm UTC](https://community.weweb.io/t/filter-on-comparison-between-fields/7693/1 "2024-03-21T13:42:00Z")

</div>

I have a table in Supabase with 2 number fields and would like to create a collection with the filter condition [field A] \< [field B]. Is this currently possible in WeWeb?  
If not, I would welcome any ideas for a workaround.

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [March 21, 2024, 6:12pm UTC](https://community.weweb.io/t/filter-on-comparison-between-fields/7693/2 "2024-03-21T18:12:01Z")

</div>

Sadly it seems it’s not possible natively with supabase

> **[Filter one column by value in second column · supabase · Discussion #5053](https://github.com/orgs/supabase/discussions/5053)**
>
> Hello, Is it possible to run a query with filters on another column's value, like: final res = await supabase .from('cities') .select('\*') .eq('columnA', 'columnB') .execute();

But it should be possible if you develop your own postgres or edge function, still more advanced.

An easier way to achieve it would be to build a formula that will return your collection and apply a front end filters, maybe by using javascript. You can ask Copilot for this 🙂

---

<div class="post-metadata">

**Author:** ![Larry](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@Larry](https://community.weweb.io/u/Larry)\
**Post date:** [March 21, 2024, 6:44pm UTC](https://community.weweb.io/t/filter-on-comparison-between-fields/7693/3 "2024-03-21T18:44:30Z")

</div>

Thanks @Alexis! I used a postgres function as a workaround which is working well.

If anyone finds this and needs the function, here it is:  
BEGIN  
RETURN QUERY  
SELECT table.id, table.name, table.comparisonfield1, table.comparisonfield2  
FROM table  
WHERE table.comparisonfield1 \< table.comparisonfield2;  
END;

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [March 21, 2024, 6:46pm UTC](https://community.weweb.io/t/filter-on-comparison-between-fields/7693/4 "2024-03-21T18:46:25Z")

</div>

Wow that’s great, well done!
