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: 6
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 15th Plane (12000 - 12499 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 12,025 Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 12 h 21 m 3 sec
Reputation Power: 628
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: 6
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 15th Plane (12000 - 12499 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 12,025 Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 12 h 21 m 3 sec
Reputation Power: 628
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: 6
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 15th Plane (12000 - 12499 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 12,025 Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 12 h 21 m 3 sec
Reputation Power: 628
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: 6
..

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 15th Plane (12000 - 12499 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 12,025 Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 12 h 21 m 3 sec
Reputation Power: 628
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: 6
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, 338 views)
File Type: jpg qinventorybygroup_table.jpg (83.1 KB, 304 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: 6
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 15th Plane (12000 - 12499 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 12,025 Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 12 h 21 m 3 sec
Reputation Power: 628
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,840 Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level)Lauramc User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 6 m 35 sec
Reputation Power: 1266
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
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
Hi,

Thanks for your reply. I will have a think about what you have said and have another bash with it all tonight.


I just thought I would explain exactly what I am trying to do here. It is very similar to kila's problem above.


I have got a table full of products:


I.e.

Product id =1 ProductName = "Widget 1" ProductCatID = 1

Product id =2 ProductName = "Widget 1" ProductCatID = 2

Product id =3 ProductName = "Widget 1" ProductCatID = 4

Product id =3 ProductName = "A Widget" ProductCatID = 5

Product id =3 ProductName = "BigWidget" ProductCatID = 6

Product id =3 ProductName = "LittleWidget" ProductCatID = 4



What I am after is only returning the table details for unique product names. So we would only have "Widget 1" once

Regards,

Tim

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Conflict with Select Distinct statement


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!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

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





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek