School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,118 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,973 people online right now. Registration is fast and FREE... Join Now!




Select only 1 copy of multiple items?

 

Select only 1 copy of multiple items?

cdietschrun

24 Jun, 2009 - 10:08 AM
Post #1

New D.I.C Head
*

Joined: 23 Jun, 2009
Posts: 24

I am super new to SQL. I am populating a drop down list on my .aspx page with a SQL DB. I am using my command text as

CODE

cm.CommandText = "select templatename,id from TBL_CHECKLIST_TEMPLATES order by templatename"



And the list is populated like:

Sample Name 1
Sample Name 1
Sample Name 1
Sample Name 2
Sample Name 2
... etc

This is obviously how the database is populated, that's fine. I just need to know how to make the drop down appear as:

Sample Name 1
Sample Name 2
Sample Name 3

I tried "distinct" in a few places but that didn't seem to work.

User is offlineProfile CardPM
+Quote Post


kmangold

RE: Select Only 1 Copy Of Multiple Items?

24 Jun, 2009 - 10:26 AM
Post #2

D.I.C Head
Group Icon

Joined: 24 Jun, 2009
Posts: 166



Thanked: 7 times
Dream Kudos: 75
My Contributions
Here is my sample SQL table:

CODE
test_table(id INTEGER PRIMARY KEY, field1 VARCHAR(45), field2 VARCHAR(45), field3 INTEGER);


Below are two ways I can get the values based off of your requirements, as long as I am understanding them properly:

CODE
SELECT field1 FROM test_table GROUP BY field1;

SELECT DISTINCT field1 FROM test_table;


Here is the same code with your table and parameter names;

CODE
SELECT DISTINCT templatename FROM TBL_CHECKLIST_TEMPLATES;

SELECT templatename, id FROM TBL_CHECKLIST_TEMPLATES GROUP BY templatename;


Although I am not quite sure why you are getting the 'id'. If 'id' is the primary key of the table, it will only return the 'id' of the first record found with the unique templatename.

This post has been edited by kmangold: 24 Jun, 2009 - 10:27 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:35PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month