简体   繁体   中英

Remove Enums from list if they already exists in database

I have a database table called DynamicText with the fields of ID , Content , and TypeEnum .

I have a list of Enums called DynamicTextEnums and I want to ensure that there is only one record per Enum in the database.

Example: I have 3 Enums called Red , White , and Blue . When creating a new record, I want to query the database to see if records already exist for the Enums. When i do, I find that records already exist for Red and Blue . I would then I want only White to appear in a drop-down list.

I'm trying to create the SQL script that queries the database and only returns the Enum values that are in the database. So if there is 7 entries for Red and 5 for Blue it would return 1 Red and 1 Blue .

Any ideas?

You could use a distinct to get unique values for TypeEnum.

SELECT distinct [TypeEnum]
FROM [app].[DynamicText]

Figured it out. I simple queried the database for the TypeEnum field and then grouped it by that column. This way I would only have one result for each Enum.

SELECT [TypeEnum]
FROM [app].[DynamicText]
GROUP BY [TypeEnum]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM