sql - distinct not working with other columns -
i trying use distinct in query
select distinct tvpauditevent.testsequenceid tvpauditevent tvpauditevent.name = 'workstepcompleted'; it works fine. , give me 100 results
but if add other columns
select distinct tvpauditevent.testsequenceid, tvpauditevent.username tvpauditevent tvpauditevent.name = 'workstepcompleted'; it gives me around 200 results, wrong. need 100 results need other columns other testsequenceid.
please let me know if there way this.
thanks
as explained in answer, distinct keyword applies columns in select statement. cannot limit 1 column.
instead, can use group by along aggregation function. instance, following returns minimum value second column:
select ae.testsequenceid, min(ae.username) tvpauditevent ae ae.name = 'workstepcompleted' group ae.testsequenceid; in fact, distinct keyword in select notational convenience. following:
select distinct col1, col2, . . ., coln table t does same thing as:
select col1, col2, . . . coln table t group col1, col2, . . . coln
Comments
Post a Comment