[英]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
. 我有一个名为
DynamicText
的数据库表,其中包含ID
, Content
和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. 我有一个名为
DynamicTextEnums
的枚举列表,我想确保数据库中每个枚举仅包含一条记录。
Example: I have 3 Enums called Red
, White
, and Blue
. 示例:我有3个枚举,分别称为
Red
, White
和Blue
。 When creating a new record, I want to query the database to see if records already exist for the Enums. 创建新记录时,我想查询数据库以查看是否已存在Enums的记录。 When i do, I find that records already exist for
Red
and Blue
. 当我这样做时,我发现
Red
和Blue
记录已经存在。 I would then I want only White
to appear in a drop-down list. 然后,我只希望
White
出现在下拉列表中。
I'm trying to create the SQL script that queries the database and only returns the Enum values that are in the database. 我正在尝试创建查询数据库的SQL脚本,并且仅返回数据库中的Enum值。 So if there is 7 entries for
Red
and 5 for Blue
it would return 1 Red
and 1 Blue
. 因此,如果
Red
有7个条目, Blue
有5个条目,则将返回1 Red
和1 Blue
。
Any ideas? 有任何想法吗?
You could use a distinct to get unique values for TypeEnum. 您可以使用distinct获得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. 我简单地向数据库查询
TypeEnum
字段,然后按该列对其进行分组。 This way I would only have one result for each Enum. 这样,对于每个枚举,我只会得到一个结果。
SELECT [TypeEnum]
FROM [app].[DynamicText]
GROUP BY [TypeEnum]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.