For some reason, the following query:
SELECT DISTINCT
Product_name,Product_title,Product_description,Product_promo
FROM Products WHERE Product_category=#Val(url.Category_id)#
ORDER by Product_promo DESC, len(Product_name)
doesn't give DISTINCT Product_name!
1. What am I doing wrong?
2. Is there a way also to limit the DISTINCT query to 10 records?
Michael.
1. distinct is applied to the entire row.
2. if you're on sql7/2k, you can use top...
SELECT top 10 DISTINCT
Product_name,Product_title,Product_description,Product_promo
FROM Products WHERE Product_category=#Val(url.Category_id)#
ORDER by Product_promo DESC, len(Product_name)
if you're on sql6x, then use rowcount
set rowcount 10
SELECT DISTINCT
Product_name,Product_title,Product_description,Product_promo
FROM Products WHERE Product_category=#Val(url.Category_id)#
ORDER by Product_promo DESC, len(Product_name)
set rowcount 0
--
-oj
http://rac4sql.home.attbi.com
"Michael Lugasy" <mic...@netvision.net.il> wrote in message
news:7aeb9057.02011...@posting.google.com...
SELECT DISTINCT top 10
Product_name,Product_title,Product_description,Product_promo,len(Product
_name) AS Product_length
FROM Product WHERE category_id=80
ORDER by Product_promo DESC, Product_length
Still - I can't get DISTINCT Product_name.
I want rows which are distinct ONLY in Product_name
and not in the "whole row", but still - to have
all other fields (Product_title/description/promo...) selected. is it
possible?
Michael.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Product_name, Product_title, ....
Name A Title 1
Name A Title 2
The server cannot make the selection for you without the
required info, so maybe you want
select product_name, max(product_title), max(....
from product
...
or use min, avg, ...
or
select product_name, product_title, ...
from product
where product_title = (select max(product_title) from product)
and ...
if you want the product_name only once, then you must say which
row; it's simply the concept of relational database
HTH
Dieter
"Michael Lugasy" <mic...@netvision.net.il> schrieb im Newsbeitrag
news:3c46ab32$0$183$7586...@news.frii.com...
You're saying that's ain't possible?
JohnNarofsky
mic...@netvision.net.il (Michael Lugasy) wrote in message news:<7aeb9057.02011...@posting.google.com>...
Point 2. set rowcount is nice. Can't use top with the distinct
keyword.
JohnNarofsky
Michael Lugasy <mic...@netvision.net.il> wrote in message news:<3c46bb24$0$190$7586...@news.frii.com>...
It should be possible using subqueries. Something like this:
SELECT DISTINCT
Product_name,Product_title,Product_description,Product_promo
FROM Products
WHERE Product_name In
(SELECT DISTINCT TOP 10 Product_name FROM Products WHERE Product_category=#Val
(url.Category_id)# ORDER by Product_promo DESC, len(Product_name))