1

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?

3
  • So what are you looking for? A SQL query that does what?
    – juergen d
    Dec 3, 2013 at 15:24
  • Sorry, should have been a bit more descriptive. I am looking for a SQL query. Dec 3, 2013 at 15:28
  • I updated my post with what I'm looking for. Dec 3, 2013 at 15:32

2 Answers 2

1

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

SELECT distinct [TypeEnum]
FROM [app].[DynamicText]
1
  • Yep, this also worked. It's probably better to use this than simply selecting all and the grouping by [TypeEnum] Dec 3, 2013 at 16:58
0

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]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.