Enforce column value is unique (distinct)

How to check or ensure that a text field is unique within the column.
I have text field that user need to keyin a value , id like to prevent user to enter an existing value from that column.

Something like ;

SELECT CASE WHEN count(distinct col1)= count(col1)
THEN 'column values are unique' ELSE 'column values are NOT unique' END
FROM tbl_name;

Thanks!

Glide doesn’t provide any native mechanism for enforcing uniqueness. To do so, you need to create your own logic in the data editor.

The general approach is to use a multiple relation that matches the column in question to itself, and then check if the relation is empty or not.

The below (copyable) concept app demonstrates how this can be done

2 Likes

Thanks again Darren for quick respond and guidance, I was thinking that if Im just missing something basic functionality within glide. Will do make some internal cross validation for desired output.

Cheers!

i cant copy your app to see how its done, can you explain it more? all the question about this topic always linked to your answer but theres nothing to see

Probably it’s because Classic Apps are deprecated now. Can you let us know what questions you have?

im making a survey app with 100 people using it as a surveyor… they will collect citizenship ID that unique for each citizen. I wanna make sure that my team dont double collect the data. thats why i need to know how to enforce column value is unique.

A simple description of a custom form is that it’s just a single row working table, a detail screen with entry components to fill it with data, and a button to take thows values and write them to a new row in a different table.

Saying that, to check for duplicates you just need a relation or query in the working table that takes the user input and looks for matches in another table. If the relation finds a match, then it would be a duplicate if you add another row with the same values.

is there any template app i can use as example? or any youtube video explaining it?

It’s pretty easy to set up, so nobody has probably created an updated template recently.

  • Create a Glide table and add one single row to it.
  • Add the appropriate user specific columns that will be used to temporarily hold user input.
  • Create a screen linked to that table and add entry components linked to those user specific columns.
  • Add a button to that screen with an Add Row action to write that user input into another table.

At a very basic level, those are the fundamentals of a custom form.

To prevent duplicates, and in your case if you acquiring a citizen ID, you would have an entry component for the user to type that ID. The ID is immediately written to the user specific column in the working table. Create a relation linking the ID to the ID is the other table that contains existing citizen data. Add a visibility condition to the button to only display if the relation is empty.

That’s your custom form. There’s more to it, such as clearing values after submitting the form, adding other verifications and warnings and such, but that should get you started.

1 Like

i still dont get the gits of it, i comes from appsheet so i am still new with all glide function.

If you follow the 4 bullet points above, where do you start to lose understanding?

1 Like