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
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 5th, 2005, 01:09 AM
fidi fidi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 fidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 14 sec
Reputation Power: 0
Using DISTINCT for some but not others in 1 query

I feel really stupid.

That doesn't happen too often..

but I feel really stupid.

SQL is completely kicking my face in right now.
So to get on with my question... (I'm kinda new to all this)

I have a gigundormous databse. I understand that if I do something like "SELECT DISTINCT CATAGORY_NAME PRODUCT_NAME" that it will not work, because although there are duplicats in CATAGORY_NAME, obviously the PRODUCT_NAME's are all going to be unique, therefore it will retrive DISTINCT for neither. This being true, I need someway to select CATAGORY_NAME distinctly, and also SELECT PRODUCT_NAME. Why not use two different queries? Good question, the reason is because I need to <cfoutput query=""> to get that loop effect going.. and if I can only output one query at a time (CF doesn't support nested queries, or atleast that's what it told me when I tried to do it) then I need to find another way to do it.

If it'll help, instead of telling you I need to do this selecting, I'll simply tell you what I'm trying to do and see if you can help me there (if not, the answer to the first question would be just STUPENDIOUS!).

I have a ginormous table. (important) Fields include "CatName" "Brand" and "ProductName". I need to be able to display it something like the following:

--CatName1---- --CatName2---- --CatName3----
---product 1--- ---product 1--- ---product 1---
---product 2--- ---product 2--- ---product 2---
---product 3--- ---product 3--- ---product 3---
---product 4--- ---product 4--- ---product 4---
---product 5--- ---product 5--- ---product 5---
-click for more- -click for more- -click for more-

I have the formatting for the table worked out. Basically it puts a <tr> when currentrow mod 4 eq 1 and it puts a </tr> when currentrow mod 4 eq 0. In other words, it gives me 4 CatNames per row. I'm sure you can see where I'm running into a problem. Since there are only about 40 catagories and 3500 products, if the CatName is not unique, I'm going to get 3500 listings. But if I don't ALSO select the ProductName in this same query, it's not going to loop, and only the first set of 40 catagories is going to have products listed under it.

The 2nd problem I'm having is how to get the first 5 products (alphebetically) under each CatName to display, although I figure I'll try this problem when I come to it. I was thinking a GROUP BY CatName ORDER BY ProductName and then do a little ditty to just pull the first 5.

Anyway, any light on any of these subjects would be wonderful. I think I'm way over my head I love you guys!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Using DISTINCT for some but not others in 1 query


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


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





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