Hi all, I am currently working on a reporting component that queries a table that holds information regarding equipment issues or failure. The UI will provide the user a means to drill down on specific data sets by selecting an issue type.
When the issue (or failure) type is selected I want to query the table and bring back equipment ids that have the issue type selected. For this the table has two columns: TypeId which identifies the type of issue reported and EquipId which contains an id for the reported equipment. When the user selects an issue type I want a second dropdown to fill with equipment ids that correspond to the issue type selected, but I need to do this in the fastest way possible so as to not take up too much SQL Server time.
My first thought is to use a simple select with distinct, such as:
While this is effective I am not sure if its performance will be good enough when the table has 10s of thousands of records.
Given that I have an Equipment table that holds the Equipment id plus other data I could also have the following query:
Perhaps there is another way that I’ve missed altogether. What do you all think? Which is the fastest way to populate the dropdown with unique items from the table? As always thank you for your time. Saga
When the issue (or failure) type is selected I want to query the table and bring back equipment ids that have the issue type selected. For this the table has two columns: TypeId which identifies the type of issue reported and EquipId which contains an id for the reported equipment. When the user selects an issue type I want a second dropdown to fill with equipment ids that correspond to the issue type selected, but I need to do this in the fastest way possible so as to not take up too much SQL Server time.
My first thought is to use a simple select with distinct, such as:
Select distinct EquipId from EquipReports
While this is effective I am not sure if its performance will be good enough when the table has 10s of thousands of records.
Given that I have an Equipment table that holds the Equipment id plus other data I could also have the following query:
select EquipId,ItemId from EquipReportsinner join Equipment on EquipReports. EquipId = Equipment.ItemIdThis will avoid the work done when DISTINCT is used, but will not return distinct records; therefore, I need to verify that the returned data item does not exist in the dropdown list before I add it. This in itself might negate the benefit if not using DISTINCT, although I can get tricky, such as building a string of equipment ids and instead of checking the dropdown I check the string.
Perhaps there is another way that I’ve missed altogether. What do you all think? Which is the fastest way to populate the dropdown with unique items from the table? As always thank you for your time. Saga
Insanity is the prelude to discovery