ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old January 21st, 2004, 04:59 PM
DoocesWild22 DoocesWild22 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 16 DoocesWild22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
trouble with DISTINCT

I have a database in access that has a lot of tables linked together with keys. I have them linked in coldfusion with a recordset like this:

SELECT Title.TitleID, Title.Title, Title.GenreID, Genre.Genre, Genre.GenreID,
artist.Artist, artist.ArtistID, Title.AlbumID, album.AlbumID, album.Album
FROM Title, Genre, artist, album
WHERE Title.GenreID=Genre.GenreID AND Title.ArtistID=artist.ArtistID
AND Title.AlbumID=album.AlbumID

When I use this, and I want just all of my artists to come up in a dynamic table, I get all of the titles, all of the artists, and all of the artists. I want to use this recordset in all of my pages, first page being artist, then album, then titles. If I do a SELECT DISTINCT, it does nothing. Besides, I just want to select the distinct artist in this case, and I need this recordset to link the page to the album page by passing the unique key of TitleID. Any ideas?

Reply With Quote
  #2  
Old January 22nd, 2004, 08:21 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,480 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 33 m 17 sec
Reputation Power: 42
Probably the reason adding DISTINCT to your query doesn't have any impact is because each combination of title, genre, artist and album is already distinct. Distinct only works when there are duplicates for the combination of all the fields in the query.

I think you are not sure what you want the query do do. How can you get only 1 artist from the query, but still get all of the albums?

Perhaps what you really want to do is order the query by artist, and then when you output the data use <cfoutput query="myquery" group="artist">? This would allow you to show the artist name 1 time, but under that output all of the albums for that artist.

Hope that helps.

Reply With Quote
  #3  
Old January 22nd, 2004, 12:24 PM
DoocesWild22 DoocesWild22 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 16 DoocesWild22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Actually that might help for my album page, after you click the artist's name. I want a list of all of the artitst under a certain letter, which I can do, but when I get all of the artists, I get one artist for every song. I want just a single listing for every artist. I can't really figure it out like this, but I have come across a different way to do it, just by making a dynamic table and linking to my album page and filtering it by the artist. I am getting my same effect, only I was hoping to use the same recordset for each page. Could anyone touch a little more on the grouping? That sounds like what I want for my album page

Reply With Quote
  #4  
Old January 22nd, 2004, 03:44 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,480 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 33 m 17 sec
Reputation Power: 42
If you only want one artist in the query, regardless of how many actual albums they have in the database, you just need to pare down the query:

SELECT
artist.Artist, artist.ArtistID
FROM artist


Assuming each artist in the artist table is unique (has it's own unique key) this should just give you 1 row for each artist. If you want to only do this for 1 letter, you can do:

SELECT
artist.Artist, artist.ArtistID
FROM artist
WHERE artist LIKE '#url.chosenLetter#%'

You could also use an SQL string function like Left() to match the letter but this is a bit more simple and cross-platform, though it is also slower. But if there aren't more than a few thousand artists the difference between using LIKE and using Left() would be small.

Reply With Quote
  #5  
Old January 22nd, 2004, 03:50 PM
DoocesWild22 DoocesWild22 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 16 DoocesWild22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That's exactly what I have done on my artist page. Now I need to know how do I use "group", just for my album page, so I can group all of the songs from one artist into just displaying the one album? Each artist will have a few albums.

Last edited by DoocesWild22 : January 22nd, 2004 at 07:49 PM.

Reply With Quote
  #6  
Old January 22nd, 2004, 03:56 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,480 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 33 m 17 sec
Reputation Power: 42
Well if you want to output the artist once, and then after that show all the albums for that artist, you'd do this:

SELECT Title.TitleID, Title.Title, Title.GenreID, Genre.Genre, Genre.GenreID,
artist.Artist, artist.ArtistID, Title.AlbumID, album.AlbumID, album.Album
FROM Title, Genre, artist, album
WHERE Title.GenreID=Genre.GenreID AND Title.ArtistID=artist.ArtistID
AND Title.AlbumID=album.AlbumID
ORDER BY Artist, Album

And then output it like this:

<cfoutput query="getAlbums" group="Artist">
<b>Artist: #getAlbums.artist#</b><br>
<cfoutput>
Album: #getAlbums.album#<br>
</cfoutput>
<br>
</cfoutput>

Reply With Quote
  #7  
Old January 22nd, 2004, 07:50 PM
DoocesWild22 DoocesWild22 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 16 DoocesWild22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This looks great, but when I try and use it, I get
Element ALBUM is undefined in GETALBUMBS. What does this mean? I have a recordset called getalbums, which the SQL is listed above...

Reply With Quote
  #8  
Old January 22nd, 2004, 09:00 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,480 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 33 m 17 sec
Reputation Power: 42
Well I just called the recordset "getAlbums". For you it would be whatever name you are giving your query in the CFQUERY tag.

Reply With Quote
  #9  
Old January 22nd, 2004, 09:58 PM
DoocesWild22 DoocesWild22 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 16 DoocesWild22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yeah I got that, so I named my query getalbums. Caps don't make a difference do they?

Reply With Quote
  #10  
Old January 23rd, 2004, 07:23 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,480 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 33 m 17 sec
Reputation Power: 42
No, CF is not case sensitive.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > trouble with DISTINCT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway