Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DISTINCT keyword syntax

Status
Not open for further replies.

rockyroad

Programmer
Feb 22, 2003
191
US
Hello,

can anyone help me with this?

ACCESS database

SELECT DISTINCT PageName, FieldName
FROM Help

doesn't work, returns every instance of PageName.

what I need is the distinct keyword applied
to the PageName column, but not necessarily to
the FieldName column.

Thank You!
 
That type of question does not make sense.

As an example

PageName ! FieldName
--------------------
hejHopp ! ditt
hejHopp ! feta
hejHopp ! nylle

What value from the fieldname column should be returned?

If you say anyone that indicates an inapropriate data model.
 
(I am going to use Oracle syntax)

if you have
SELECT PageName, max(FieldName) FROM Help GROUP BY PageName;
you would get the result you seem to want. (depending on the type of Field Name, several other aggregate functions could work) no matter which function you chose you will not get the distinct value of PageName, FieldName but rather a distinct pagename and some example of FieldName I tried to remain child-like, all I acheived was childish.
 
it is a common error

many people think DISTINCT applies to the column name that follows it -- which it does, as long as that's the only column that follows it

DISTINCT means distinct rows -- i.e. all combinations of values for all columns in the SELECT list

rockyroad, if you want the distinct PageName values, don't put any other column in the SELECT list

if you also want some other column along with the distinct PageName values, then use jimbopalmer's syntax, but be aware, as swampboogie suggested, your conceptual model may be deficient...


rudy

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top