How can I query out the result based on multiple values in text input

I want user to enter multiple UUIDs in the text input and then in back end use all these multiple UUIDs in where clause of SQL query to fetch results.

Hi Shriniket!
Here are two ways you can include multiple IDs from an input in there where clause of a SQL query:

  1. Use .split() to turn your text input into an array
    SQL Query:
    SELECT * FROM users WHERE uuid = ANY({textinput1.value.split(",")}})
  2. Use a multiselect input component. Provide your users with a dropdown of all IDs and let them select multiple IDs.
    MultiSelect VALUES field: {{query1.data.uuid}}
    SQL Query:
    SELECT * FROM users WHERE uuid = ANY({{multiselect1.value}})
    Hope this helps! Let me know if you have any followup questions.

@jane , thank you for laying this out! I am trying to use the multiselect input method to filter the results of a pie chart. However, it is not working like a charm for me:

Forgive my complicated chunk of SQL, but I don’t see why I keep getting a syntax error at line 11. I was able to get a dropdown input to filter the chart, but not the multiselect. This is my WHERE clause for the dropdown that worked: WHERE pub.publication_name = {{select1.value}} or {{select1.value}} IS NULL

Hi Jane!
This doesn't seem to work for me, I also tried setting the multi-select values to {{ states.data.Property_State }} but this seems to fetch an empty array

Thanks for your help

Hello @sergio,

You are using a MySQL DB, for that, use this syntax:-

select * from users where id IN ({{ [1, 2, 3] }})\

For more information on this and the different syntaxes for the various DBs, check out the SQL Cheatsheet

1 Like

Thank you! I totally overlooked that cheatsheet before, amazing