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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct help

Status
Not open for further replies.

twcman

Programmer
Jun 28, 2001
284
0
0
US
Why would this query return duplicate reportnumber records when I am using the distinct reportnumber in the select statement?

SELECT DISTINCT reportnumber, lpatname + ',' + fpatname AS patname,reportdate,hideview,reportid,physicianid,ssn,signdate,locked,mdedit,transedit FROM reports
WHERE origuserid = 9
ORDER BY reportdate desc


Thanks..............

Chris Scott
The Whole Computer Medical Systems
 
Because you are probably selecting an id field in which that record with that id has a report number. These individual id's may reference a similar report number. Your query will return distinct records, not necessarily reportnumbers.
 
because DISTINCT operates on the ENTIRE SELECT LIST
You should use group by instead

GracefulWebDevelopment.com
 
How would you recode the query above or the cfoutput to use group by?



Chris Scott
The Whole Computer Medical Systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top