Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Using SQL Distinct.. Help!
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using SQL Distinct.. Help!

 Post Reply Post Reply
Author
nkewney View Drop Down
Newbie
Newbie


Joined: 08 October 2004
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote nkewney Quote  Post ReplyReply Direct Link To This Post Topic: Using SQL Distinct.. Help!
    Posted: 08 October 2004 at 10:50am

Hi there,

I was hoping someone could help me with a problem I have with an SQL query.

There are some instances in the database where there are entries with the same 'item_product_code', but with different prices depending on the item_stone_field (see sample below)

What i need to do is get some SQL to return all UNIQUE item_product_code fields, and if there are more than one, just list the first. (The rest will be dealt with in another query).

item_id item_supplier item_product_code item_ cat_finish  item_cost_price  item_stone
28 2  1016   Sterling   6.95   green
29 2  1016   Sterling &nb sp;6.95   black 
30 2  1016   Sterling   4.95   blue
33 2  1014   Sterling   4.95   blue

This is my latest attempt which unforunately doesn't work!!

Sql = "SELECT DISTINCT(item_product_code), item_cost_price FROM Products WHERE Products.item_cat_prodtype ='" & insBrowse & "' GROUP BY item_product_code, item_cost_price "

Any suggestions?

Cheers

Nick

Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 08 October 2004 at 8:14pm
SELECT TOP 1 ... should do it.
Back to Top
nkewney View Drop Down
Newbie
Newbie


Joined: 08 October 2004
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote nkewney Quote  Post ReplyReply Direct Link To This Post Posted: 09 October 2004 at 2:55am

Will 'top' work if i want to return the first of every similar entry in the table?

Nick

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 09 October 2004 at 3:59am
Not for that, no. Can you run it through query analyser and show us the output and tell us what you want it to look like?
Back to Top
nkewney View Drop Down
Newbie
Newbie


Joined: 08 October 2004
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote nkewney Quote  Post ReplyReply Direct Link To This Post Posted: 09 October 2004 at 12:44pm

Thanks for your help so far.

This is the query I'm using...

SELECT DISTINCT (item_product_code), item_cost_price
FROM Products
WHERE Products.item_cat_prodtype='rings'
GROUP BY item_product_code, item_cost_price;

This is the result I'm getting.

(I only require the first of any duplicate product code, ommitting any further entries...)
 

item_product_code item_cost_price
1007 6.35
1008 4.75
1016 4.95
1016 6.95
1018 6.25
1018 6.95
1022 9.95
1023 3.95
1023 6.50
1026 7.50
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.