Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Select Distinct Help
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

TStewartFan
Junior Member

190 Posts

Posted - 13 March 2005 :  10:32:59  Show Profile  Visit TStewartFan's Homepage
I am having a slight problem with dynamically populating a pulldown list with values form my Access database. I am trying to display results without the duplicate entires but when my sql executes all fields found in the db are pulled and not just the SELECT DISTINCt. Can someone help with the following sql statement:

strSql = "SELECT DISTINCT " & strTablePrefix & "MUSIC.M_ID"
strSql = strSql & ", " & strTablePrefix & "MUSIC.M_ARTIST"
strSql = strSql & ", " & strTablePrefix & "MUSIC.M_MEMBER_ID"
strSql = strSql & " FROM " & strTablePrefix & "MUSIC "
strSql = strSql & " WHERE " & strTablePrefix & "MUSIC.M_MEMBER_ID = 0 "
strSql = strSql & " ORDER BY " & strTablePrefix & "MUSIC.M_ARTIST ASC;"
set rsMusic = Server.CreateObject("ADODB.Recordset")
rsMusic.open strSql, my_Conn, 3
artistRows = rsMusic.getRows
rsMusic.Close
Set rsMusic = nothing

Edited by - ruirib on 13 March 2005 16:31:43

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 13 March 2005 :  11:59:03  Show Profile  Visit D3mon's Homepage
So you've got:

SELECT DISTINCT [tblprefix]MUSIC.M_ID,
[tblprefix]MUSIC.M_ARTIST,
[tblprefix]MUSIC.M_MEMBER_ID,
FROM [tblprefix]MUSIC
WHERE [tblprefix]MUSIC.M_MEMBER_ID = 0
ORDER BY [tblprefix]MUSIC.M_ARTIST ASC;

Looks like you're asking it to select all the distinct ID numbers (MUSIC.M_ID). If the ID field is unique, then all the records will be returned.

Also, aince all your fields come from the same table, you shouldn't need to specify the table alias in your select fields or order by, or where clauses:

SELECT DISTINCT M_ID,
M_ARTIST,
M_MEMBER_ID,
FROM [tblprefix]MUSIC
WHERE M_MEMBER_ID = 0
ORDER BY M_ARTIST ASC;


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

TStewartFan
Junior Member

190 Posts

Posted - 13 March 2005 :  12:50:09  Show Profile  Visit TStewartFan's Homepage
Thanks. I have actually fixed issue number one just to bring to surface issue number 2. My select distinct and group by function now works but my when selected function fails because it is being grouped. However it is no longer an sql error so its back to web surfin I go...heh By the way the new sql statement looks like this:

strSql = "SELECT DISTINCT M_ARTIST, SUM(M_ID)"
strSql = strSql & " FROM " & strTablePrefix & "MUSIC "
strSql = strSql & " GROUP BY M_ARTIST"
strSql = strSql & " ORDER BY M_ARTIST ASC;"

Edited by - TStewartFan on 13 March 2005 12:55:02
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07