# Dynamically Select from different Tables based on Column value

**URL:** https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880
**Category:** Ask for Help
**Created:** [February 7, 2025, 2:57pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880 "2025-02-07T14:57:15Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Sean\_Page](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sean_page/32/77424_2.png) [@Sean\_Page](https://community.glideapps.com/u/Sean_Page)
#### Post date: [February 7, 2025, 2:57pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/1 "2025-02-07T14:57:15Z")

</div>

I would like to be able to do a lookup from different tables based on the value of a column which relates to the table name.

**Here are the tables and the relationships:**

1. Data Type Table where the “table” column is the name of the table the value will be stored  

2. Parameter Table with Data Type Id column relates to the Data Type table above  

3. Parameter by Project Table where the Parameter Id column relates to the Parameter Table above and the Value Id column relates to the row in the Parameter String table below in this example.  

4. Parameter String table example where the final value is written  

The final result would be to get the “value” from the parameter\_string table (Image 4) in the parameter\_by\_project table (Image 3) as a lookup or query or something. Is this possible to dynamically get tables and then values?

Thank you in advance for any help you’re willing to provide!

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 8, 2025, 12:03am UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/2 "2025-02-08T00:03:06Z")

</div>

> [@Sean\_Page](#):
>
> Is this possible to dynamically get tables and then values?

Not natively. My idea would be to create multiple query columns for each of the possible table name. Create lookups or joined lists. Then create if then else and return the right column based on the table name in the conditions.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 8, 2025, 12:04am UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/3 "2025-02-08T00:04:14Z")

</div>

It will be really complicated and not easy to maintain… What are you trying to do in the app? What is the flow? Maybe we could give you advices and recommendations on how to implement alternative solutions.

---

<div class="post-metadata">

### Author: ![Sean\_Page](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sean_page/32/77424_2.png) [@Sean\_Page](https://community.glideapps.com/u/Sean_Page)
#### Post date: [February 10, 2025, 1:02pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/4 "2025-02-10T13:02:31Z")

</div>

Thanks for the responses @MaximeBaker.

Here is a rundown of the app / process.

We are building a comparison app that will look at historical project costs and then use industry data to inflate those prices to today’s dollars.

1. Create a Comparision  
A. Assign two or more projects  
B. Assign Factors that will affect the cost

2. Assign Parameters to each Project with various data types and not all projects have the same parameters or values.  
A. Project 1 may have a Boolean, String, and Double  
B. Project 2 may have an Integer and Text

3. The way the Parameters are set up is such they are just Key / Value pairs essentially based on that data type.

4. Then when I want to call the values (Relation / Lookup) the table they will come from will be dynamic based on the data type and the parameter which changes often.

Honestly if this isn’t a very easy thing to do, I am working with PGSQL so I can just make a view with the info, just means a lot more hoops for all the CRUD stuff, but I have done it before.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 1:11am UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/5 "2025-02-13T01:11:04Z")

</div>

I mean yeah, if you want to keep the data structures that way (good relations by the way, I like generic things) you might want to do it from SQL. It is possible from Glide tho. But if you want to reuse these views, then you should create them in the database. The only thing that would not work is that I don’t think you can use SQL views in Glide. Or is it ? With read-only table queries? @ThinhDinh

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [February 13, 2025, 1:13am UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/6 "2025-02-13T01:13:46Z")

</div>

I haven’t used SQL at all in Glide so gonna sit this one out.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 1:16am UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/7 "2025-02-13T01:16:18Z")

</div>

Found it! Yes it is possible!

> **[PostgreSQL | Glide Docs](https://www.glideapps.com/docs/essentials/data-sources/postgresql#creating-a-read-only-table-with-a-query)**
>
> Read and write data to your PostgreSQL database.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 1:16am UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/8 "2025-02-13T01:16:56Z")

</div>

@Sean_Page You can use a custom query to call your view!

---

<div class="post-metadata">

### Author: ![Sean\_Page](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sean_page/32/77424_2.png) [@Sean\_Page](https://community.glideapps.com/u/Sean_Page)
#### Post date: [February 13, 2025, 1:37pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/9 "2025-02-13T13:37:27Z")

</div>

Thank for the follow up @MaximeBaker, I did end up going with a View from Postgres. I have done this successfully many other times, but was hoping to need all the extra hoops this approach brings with it.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 1:55pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/10 "2025-02-13T13:55:23Z")

</div>

Did you create a custom query from Glide to get data from that view?

---

<div class="post-metadata">

### Author: ![Sean\_Page](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sean_page/32/77424_2.png) [@Sean\_Page](https://community.glideapps.com/u/Sean_Page)
#### Post date: [February 13, 2025, 2:08pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/11 "2025-02-13T14:08:59Z")

</div>

No, you can load a view just like you do a regular table from Postgres so I created it in the actual DB so I would have access to it for other applications like PowerBI as well.

Then if you use a single relation to any “real” tables you can use any normal Data Operation on that as the “Item” when editing or adding.

 ![Glide View](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/8/b88a7e400c02ae6b5e3ba540712d303b73abf47a.png)

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 2:27pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/12 "2025-02-13T14:27:00Z")

</div>

What would happen if you edit data from Glide on the view? I don’t think it will work… I don’t know postgres a lot, but I know that editing data from view in MSSQL is not possible…

> You cannot directly update a view in SQL. However, you can update the underlying table data that the view references, and the changes will be reflected in the view when queried.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 2:27pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/13 "2025-02-13T14:27:20Z")

</div>

That is why I talked about the read only custom query.

---

<div class="post-metadata">

### Author: ![Sean\_Page](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sean_page/32/77424_2.png) [@Sean\_Page](https://community.glideapps.com/u/Sean_Page)
#### Post date: [February 13, 2025, 2:42pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/14 "2025-02-13T14:42:47Z")

</div>

Correct, you do not edit the View, but that is why you put the relationship column to the table you do want to edit. Then you can pick that item to edit, update, or delete etc.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/2/e20aa572c8f4ce61e5d8744f81cc9b7a8f012796.png)

This is the first pain that you now have to do everything somewhere else, and the other one is now every operation you make needs to call a Reload Query of the View.

These things aren’t major obstacles, but something to be aware of.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 2:50pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/15 "2025-02-13T14:50:19Z")

</div>

You mean that you can delete a row from a foreign key? It allows you to do that? 🤯 From Glide?

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [February 13, 2025, 2:59pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/16 "2025-02-13T14:59:11Z")

</div>

Yes. You can delete single or multiple rows through a relation or query.

---

<div class="post-metadata">

### Author: ![Sean\_Page](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sean_page/32/77424_2.png) [@Sean\_Page](https://community.glideapps.com/u/Sean_Page)
#### Post date: [February 13, 2025, 3:02pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/17 "2025-02-13T15:02:09Z")

</div>

Yes, I do it quite often as views are much easier to get the data that I want for Filtering / Grouping since I can’t do that with Lookup columns. If we could use Lookups for those things I would use significantly less views.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [February 13, 2025, 3:03pm UTC](https://community.glideapps.com/t/dynamically-select-from-different-tables-based-on-column-value/79880/18 "2025-02-13T15:03:48Z")

</div>

I mean from a custom query in read only.
