How do I do a drop-down list without duplicate elements?

excel dynamic drop down list remove duplicates
excel drop down list remove used items
dependent drop down list excel
dynamic drop down list excel
excel dynamic list & remove duplicates
pivot table drop down list
how to link drop down list to pivot table
distinct values in drop down list in google sheets

I have a list of objects and multiple drop-downs. I want to display the data from the list. But my problem is that I didn't want to have something like this:

For example: I don't want to have in drop-down a file name for two times :

file1
file1
file2
file3
file3

I want to have only: file1, file2, file3

This is my controller where I put the list in model

@GetMapping("/filter/functionality/misramessages")
public String filterFunctionality(Model model) {
    model.addAttribute("misraMessages", misraMessagesService.findAllMisraMessagesFromDb());
    return "functionality";
}

And after in html I do this:

 <!-- Filter File Name-->
        <div class="form-group row">
            <label for="fileName" class="col-sm-2 col-form-label">File Name</label>
            <div class="col-sm-10">
                <select class="form-control"  name="file_name" id="fileName">
                    <option th:value="0" text="Please Select"></option>
                    <option  th:each = "misra : ${misraMessages}"
                             th:value="${misra.fileName}"
                             th:text="${misra.fileName}">
                    </option>
                </select>
            </div>
        </div>

<!-- Filter Message Number-->
        <div class="form-group row">
            <label for="messageNumber" class="col-sm-2 col-form-label">Message Number</label>
            <div class="col-sm-10">
                <select class="form-control"  name="message_number" id="messageNumber">
                    <option th:value="0" text="Please Select"></option>
                    <option  th:each = "misra : ${misraMessages}"
                             th:value="${misra.messageNumber}"
                             th:text="${misra.messageNumber}">
                    </option>
                </select>
            </div>
        </div>
        .......
        .......

Its always better not to bring in duplicates to memory if that is causing issues and duplicate removal is needed.

So instead of using repository method - misraMessagesRepository.findAll(); , you need to write a new method in that repository which returns DISTINCT results and use that method in DAO.

@Query("SELECT DISTINCT * FROM MESSAGES_TABLE" , nativeQuery = true)
List<MisraMessages> findDistinctMessages();

You haven't shown your repository so I used dummy table name. Show your repository code and Entity details if still confused and need better answer.

Unique Data Validation Drop-Down From Duplicate Table Data , We want the drop-down list to contain a unique list of reps from the table. -​university.com/use-power-query-to-create-a-drop-down-list-without-duplicates/ to dynamically adjust as the number of PivotTable items change. now in sheet 1. B2 -> Press Alt-A-V-V-Allow-List-on source press F3-> choose dropdown which was you created as name manger. Check the attached fiel. Attached Files. A drop down list with no duplicates.xlsx‎ (21.1 KB, 10 views) Download. Register To Reply.

Well I expect that misraMessagesService.findAllMisraMessagesFromDb() is returning list of String. So you can do something like this if you don't want to change your findAllMisraMessagesFromDb() method:

List<String> messages = misraMessagesService.findAllMisraMessagesFromDb();
Set<String> uniqueMsgs = new HashSet<String>(messages);

or you can also create a new method in misraMessagesRepository:

@Query("SELECT DISTINCT name FROM MisraMessages")
public List<MisraMessages> findDistinctMisraMessagesFromDb();

either of the two will work.

Data validation without duplicates - Excel Tricks, Create a drop-down data validation list in Excel, that only shows unique items ways you can do this– for example, using the Remove duplicates feature, or a  Re: Drop Down List without Duplicates one way is to use a pivot table somewhere to return a unique list then use that in your validation. refresh pivot table if you think new names may have been added

Never go for JAVA way to do the same because it is simply double processing time.

I would avoid processing in Java level code as it is easily possible by query level.

Just use Select distinct keyword and it works like a charm..!!

Keep it simple.

Excel Formula - Extract unique items for drop-down list, The COUNTIF function counts previous values above to make sure that no duplicates are displayed. If no values in previous cells above are  Well I expect that misraMessagesService.findAllMisraMessagesFromDb() is returning list of String. So you can do something like this if you don't want to change your findAllMisraMessagesFromDb() method: List<String> messages = misraMessagesService.findAllMisraMessagesFromDb(); Set<String> uniqueMsgs = new HashSet<String>(messages);

Convert your List into Set. It will remove your duplicates then put into model.

Populate drop down list with unique distinct values sorted from A to Z, This article explains how to build dependent drop down lists. No excel formulas​; Easily copy values: Each drop down list is linked to the cell behind. but the unique values some how are giving duplicate values for me. We simply Allow a List equal to the name, dd_reps, as shown below. The resulting drop-down contains a list of choices from the PivotTable, as shown below. Once the workbook is set up, as new data is added to the table each period, you just need to Refresh the PivotTable and any new reps will flow through the PivotTable into the drop-down.

Create dependent drop down lists containing unique distinct values, Step 1 - With the original names in column A, put this array formula¹ somewhere off to the right in the second row. I'll use Z2. You will now have the dropdown list containing the unique values. However, you will also notice that the dropdown list includes the empty cells too. The size of the list changes depending on the values in the source table. Thus, the formula should be changed into one that automatically adjusts the range.

Data validation - Drop down list with no duplicates in excel, In this article, I'll show you how to do this in a Table object using structured There's no built-in duplicate rule for Excel's Data Validation feature, but tips for using Outlook 2016's AutoComplete list efficiently (TechRepublic)  3) Create the drop down list and use as a source the table you just created. And that’s all! See below how the drop down list automatically captures new values when you add them below the list. Back to top. Create dependent drop down lists. Another thing you can do is to limit the choices in a drop down list based on the selections of another

Use Excel data validation to prevent duplicate values in a column , I am having data validation dropdown in A1 to select from EMPID. formula to have the dropdown with only unique values without duplicates? You will need to generate a unique list somewhere and then create DV on this  I have a field in a list with the type drop down. It is supposed to show available countries which works. However, there are a lot of annoying duplicates of the same country.

Comments
  • There are several ways to eliminate duplicates. You could even try to eliminate them in your database query, maybe using the DISTINCT keyword. You could as well eliminate them in the method misraMessagesService.findAllMisraMessagesFromDb() using Java. What do you prefer? How does the method look?
  • It is simple : @Override public List<MisraMessages> findAllMisraMessagesFromDb() { return misraMessagesRepository.findAll(); }
  • Then have a look at the database query. You should be able to eliminate duplicates there. See the answers given below.
  • I did like you told me but I received this error : Validation failed for query for method public abstract java.util.List com.cidashboard.repositories.MisraMessagesRepository.findDistinctMessages()!
  • I need to annotate the entity with @NamedNativeQuery(name = ... ) ?
  • @Alexandra : I updated answer with nativeQuery = true . Try that.