How to get a list of unique values for a given column from TDataset lazarus / 16-Databases ---------------------------------------------------------------------- stoffman · 2021-11-04 14:11 Hi, Is there a "standard" way to get all the unique values for a given column in TDataset? I can loop my self and find them, but I'm sure I'm not the first one to encounter this problem so I'm looking for more official way. EDIT: To be sure the data source is not a database, and I explicitly wish to achieve this with data already loaded into a dataset  Thanks, ---------------------------------------------------------------------- SymbolicFrank · 2021-11-04 14:31 I would add them to a TStringList with duplicates turned off. ---------------------------------------------------------------------- devEric69 · 2021-11-04 14:41 Depending on the database, the SQL keyword DISTINCT or DISCTINCTROW exists. ---------------------------------------------------------------------- Zvoni · 2021-11-04 15:03 Nevermind, if that column is already defined as "UNIQUE" then you just SELECT it, since the DB enforces uniqueness of values for that column ---------------------------------------------------------------------- stoffman · 2021-11-04 15:47 @zvoni @devEric69 The data source is not a database. @SymbolicFrank That seems like an option. Are there any alternative (assuming the column is not a string and I would like to avoid the conversion) ? ---------------------------------------------------------------------- mangakissa · 2021-11-05 14:46 Quote from: stoffman on November 04, 2021, 03:11:08 pmHi, Is there a "standard" way to get all the unique values for a given column in TDataset? I can loop my self and find them, but I'm sure I'm not the first one to encounter this problem so I'm looking for more official way. EDIT: To be sure the data source is not a database, and I explicitly wish to achieve this with data already loaded into a dataset  Thanks, Do you fill the TDataset with a file? If it is you have to manage it before loading it. If the dataset is already loaded and want to get unique values, SymbolicFrank gives you the only way. Must the data showed in the grid after finding uniqueness? ---------------------------------------------------------------------- stoffman · 2021-11-05 15:37 Quote from: mangakissa on November 05, 2021, 03:46:18 pmDo you fill the TDataset with a file? If it is you have to manage it before loading it. If the dataset is already loaded and want to get unique values, SymbolicFrank gives you the only way. Must the data showed in the grid after finding uniqueness? Yes, from a file. And as I said I explicitly wish to achieve this after the data already loaded into the dataset. The dataset may or may not be shown in a Grid. Why does it affect the solution? ---------------------------------------------------------------------- avk · 2021-11-05 15:46 Didn't check if this would work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  uses  ..., Generics.Collections;...type  TVarList = specialize TList; function GetUniqList(d: TDataSet; const aFieldName: string): TVarList;var  s: specialize THashSet;  v: Variant;begin  Result := TVarList.Create;  s := specialize THashSet.Create;  try    d.First;    while not d.EOF do      begin        v := d.FieldByName(aFieldName).Value;        if s.Add(v) then          Result.Add(v);        d.Next;      end;  finally    s.Free;  end;end;