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

Select Statement I Need HELP!!!!

Status
Not open for further replies.

bmann

Programmer
Oct 8, 2002
128
0
0
US
I need a distinct select statement that is distinct on ORI and displays just one agency. I need one disinct ori and then displays agency. Agency might have 3 different agencies tied to ORI CA900000. I only want to display one of the agencies. It does not mater which one. Example data.

ORI Agency
CA900000 Department of Health


SELECT DISTINCT ORI, agency
FROM CP_USER
WHERE (COUNTY = 'alameda')
 
Distinct works on all the columns not just one, so if you have 3 different agencies for ORI, you will see 3 rows, with the same ORI and each differnt agency.
 
If you don't care what agency you get:
Code:
SELECT ORI, MAX(agency) AS agency
FROM         CP_USER
WHERE     (COUNTY = 'alameda')
GROUP BY ORI

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
I would think the previous post would work.
If not
1. Can you use distinct for just one column
e.g. select (distinct ori), ...etc. ... from ...
2. If not I think you could use Group by


Oakgrove Computer Grouper
Lansing, MI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top