Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

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 ASP Free Forums Sponsor:
  #1  
Old June 18th, 2004, 08:44 AM
kila kila is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 90 kila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 33 m 59 sec
Reputation Power: 5
Conflict with Select Distinct statement

Guys,
I have storefront recordset. I want to assign each product to several different categories. However when I use the following code, the product shows up 3 times in one category listing:
___________
sqlQry = "SELECT * FROM qInventoryByGroup WHERE itemname LIKE 'fsgfx%' ORDER BY "
If sortby = "saleitems" Then
If how = "asc" Then
sqlQry = sqlQry & "ONSALE ASC, MANUF ASC, ITEMNAME ASC;"
arrow1 = "<img src=""img/sort-asc.gif"" width=8 height=7 alt=""Now sorted by: Sale Items, Ascending"" hspace=2 border=0 align=middle>"
___________

So i inserted ye old Select Distinct Itemname, which should solve my problem, however it causes the following error:

Microsoft OLE DB Provider for ODBC Driverserror '80040e07'
[Microsoft][ODBC Microsoft Access Driver] ORDER BY clause (MANUF) conflicts with DISTINCT.


I don't understand why the order by should conflict with the select distinct, I am only specifying to select distinct within the 'Itemname' column.. help!

Reply With Quote
  #2  
Old June 18th, 2004, 08:53 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 452
Get distinct itemnames.
Code:
SELECT DISTINCT ItemName 
FROM qInventoryByGroup
WHERE ItemName LIKE 'fsgfx%'

Then you could probably do this

Get everything associated with those distinct itemnames.
Code:
SELECT * 
FROM qInventoryByGroup
WHERE ItemName IN
( 
   SELECT DISTINCT ItemName
   FROM qInventoryByGroup
   WHERE ItemName LIKE 'fsgfx%'
)
ORDER BY ItemName

Reply With Quote
  #3  
Old June 18th, 2004, 09:15 AM
kila kila is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 90 kila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 33 m 59 sec
Reputation Power: 5
Didn't work

Well Memnoch that seemed to fix the error, but I still have the problem that when I assign a record to more than one category, this select statement shows the same product duplicated, once for each category.

My storefront is set up to have products in several categories at once, but for some reason this select statement is not picking out the actual distinct record.

Reply With Quote
  #4  
Old June 18th, 2004, 10:13 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 452
Be more specific about how the products are assigned, and how you want them returned.

Reply With Quote
  #5  
Old June 18th, 2004, 10:37 AM
kila kila is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 90 kila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 33 m 59 sec
Reputation Power: 5
Specifically;

Ok,



This is how the records are currently displayed, in the paged recordset. For some reason if i assign a file to more than one category, it shows up more than once on this screen.

I am selecting the files for this page by the wildcard LIKE statement 'LIKE 'fsgfx%': fsgfx is the root inventory name for graphic files.

In addition to this inventory naming convention, files are also organized by a 'group' field in the database, i.e., what you see in the dropdownbox on the top of the screen. Flyer layouts, illustrations, etc.

What I am intending to do is add some more 'groups' to further organize the files by musical genre.. which is fine, I -can- add the groups and assign records to several categories, but the problem is that the URL above (using the SELECT statement i provided earlier) does not recognize that an individual record should not be displayed 3 times in this page just because it has 3 categories. It should only show up once.

Thanks

Reply With Quote
  #6  
Old June 18th, 2004, 10:41 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 452
It seems that you should be selecting the Category, then get all of the items in that category. Instead of selecting and item and and returning it's categories...

Reply With Quote
  #7  
Old June 18th, 2004, 10:53 AM
kila kila is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 90 kila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 33 m 59 sec
Reputation Power: 5
..

Ok, I tried it the other way around, but still the same result; when I assign a product to more than one category, i get dupes.

sqlQry = "SELECT * FROM qInventoryByGroup WHERE ItemName IN (SELECT DISTINCT ItemName FROM qInventoryByGroup WHERE GroupName LIKE 'Graphics%') ORDER BY "



Here is the qinventorybygroup SQL if it helps:
SELECT TBLINVENTORY.ITEMID, TBLINVENTORY.SKU, TBLINVENTORY.ITEMNAME, TBLINVENTORY.DESCRIP, TBLINVENTORY.ONSALE, TBLINVENTORY.SALEDISCOUNT, TBLINVENTORY.COST, tblInv_Units.UNIT, TBLINVENTORY.SHOWIT, TBLMANUFACTURERS.NAME AS ManufName, TBLGROUPS.NAME AS GroupName, tblInventoryGroups.GroupID, TBLINVENTORY.MANUF, TBLINVENTORY.IMG_SMALL AS Thumbnail
FROM TBLMANUFACTURERS, TBLINVENTORY, tblInv_Units, TBLGROUPS INNER JOIN tblInventoryGroups ON (TBLGROUPS.GROUPID = tblInventoryGroups.GroupID) AND (TBLGROUPS.GROUPID = tblInventoryGroups.GroupID)
WHERE (((TBLINVENTORY.SHOWIT)=-1) AND ((TBLINVENTORY.MANUF)=[tblManufacturers].[ManufID]) AND ((TBLINVENTORY.UNIT)=[tblInv_Units].[ID]) AND ((tblInventoryGroups.ItemID)=[tblInventory].[ItemID]))
ORDER BY TBLMANUFACTURERS.NAME;

Reply With Quote
  #8  
Old June 18th, 2004, 11:01 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 452
If your database is access, try zipping it and uploading it and I will take a look at it...

Or just post the table structure of qInventoryByGroup (assuming this is the only relevant table) and some sample (duplicated) data.

Reply With Quote
  #9  
Old June 18th, 2004, 02:06 PM
kila kila is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 90 kila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 33 m 59 sec
Reputation Power: 5
Table structure

I've attached two snapshots of the db.. the table view is minus the columns which i'm sure don't impact this statement.

Quote:
Originally Posted by Memnoch
If your database is access, try zipping it and uploading it and I will take a look at it...

Or just post the table structure of qInventoryByGroup (assuming this is the only relevant table) and some sample (duplicated) data.
Attached Images
File Type: jpg qinventorybygroup_design.jpg (35.9 KB, 311 views)
File Type: jpg qinventorybygroup_table.jpg (83.1 KB, 281 views)

Reply With Quote
  #10  
Old June 23rd, 2004, 08:24 AM
kila kila is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 90 kila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 33 m 59 sec
Reputation Power: 5
Select Distinct problem..

Quote:
Originally Posted by kila
I've attached two snapshots of the db.. the table view is minus the columns which i'm sure don't impact this statement.

Memnoch, I hate to quote myself but you seem to be the man with the answers. Can you have a quick look at the screenshotsI attached in the previous message.

Thanks.

Reply With Quote
  #11  
Old December 8th, 2004, 06:25 AM
Techy Techy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 6 Techy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Same here

Hi Guys,

Did you solve this problem?

I have exactly the same problem here with a simular database setup.

Here is my SQL:

SELECT *
FROM Products
WHERE ProductName IN (
SELECT DISTINCT Productname
FROM Products)
ORDER BY Ordered_count DESC;

It still does not return a distinct product name, please help!

Regards,

Techy

Reply With Quote
  #12  
Old December 8th, 2004, 10:00 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 452
Try doing a DISTINCT on the outer part of the query as well.

Reply With Quote
  #13  
Old December 9th, 2004, 07:39 AM
Techy Techy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 6 Techy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Memnoch
Try doing a DISTINCT on the outer part of the query as well.
Tried that, still not joy

Regards

Tim

Reply With Quote
  #14  
Old December 9th, 2004, 01:34 PM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,783 Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 15 h 48 m 56 sec
Reputation Power: 1095
OK after looking at this, you might try something a little different. It looks to me like your code should just be:

SELECT * FROM Products

The (SELECT DISTINCT Productname FROM Products) will return ALL of the product names in the product table (one of each name). So if there are 100 different names of different products, that portion of the query alone would yield 100 results, so you would get 100 results for every product in the table.

If you decide which product name(s) you are looking for you could say for example:
SELECT *
FROM
Products
WHERE
Productname in ('Widgets','Wigwams','Screwdrivers')

Therefore start by selecting the distinct product names. Get just the names you want and insert them into the parentheses as I have done above, separating each with a comma and enclosing the names in a single quote ('). This only works if you are looking for products with a specific name, however.

I hope that helps!

Reply With Quote
  #15  
Old December 10th, 2004, 10:24 AM