Link to home
Start Free TrialLog in
Avatar of GTC-KTX
GTC-KTXFlag for United States of America

asked on

only unique values in query

the following is the rowsource for a combobox.

SELECT SUPPLIERpricing.ID, SUPPLIERpricing.TERM
FROM SUPPLIERpricing
ORDER BY SUPPLIERpricing.TERM;

this query returns
12
12
24
24
24

i want it to only return a number once
12
24

how can i adjust my query to do this

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or (wrong field...) :


SELECT SUPPLIERpricing.TERM
FROM SUPPLIERpricing
ORDER BY SUPPLIERpricing.TERM;

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For a combo box... maybe you're displaying the Term field (as the Label), and the Value is the ID field. In which case, you want to decide which ID you want, and maybe use:

SELECT MIN(ID) as ID, TERM
FROM SUPPLIERpricing
GROUP BY TERM
ORDER BY TERM;

Rob
Avatar of GTC-KTX

ASKER

selectdistinct isn't working for me.

Rob,
your methods do not get rid of the multiple similar values, it simply groups them, is that correct
You propose two fields for one column in your original question, what's field do you want to output on each row ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
GROUP BY and DISTINCT are very similar, except that GROUP BY will allow aggregate functions to be used. Because you have a second field involved, you should use GROUP BY and have an aggregate function on the other field.

Rob
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Shru - I think you mean to partition by TERM, not ID. And you can't use ORDER BY in the subquery (the one outside the OVER clause).

@GTC - Shru's code is designed to create a FIRST(ID) kind of functionality.

Rob
Avatar of GTC-KTX

ASKER

Guys,
I think i sent you on a wild goose chase.  My query was not intended to have the field ID.  So from your posts you called that to my attention.  Once this was removed, it is a simple Select Distinct.  As far as points, i am just splitting up evenly by all that responded.  Thanks for taking the time to help!
Thanks for the points!