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!

DISTICT from two columns

Status
Not open for further replies.

andnos

Technical User
Nov 21, 2005
48
US
I have this SQL statement:

Code:
SELECT DISTINCT co_name, id  FROM user

id is a unique number
co_name has many values that are the same, I am looking for something that will select the first DISTINCT co_name and the id associated with it.

The above SQL doesn't do this, because I think it selects the unique id and the co_name.
 
the first DISTINCT co_name? you mean. the lowest value in the table?

could you perhaps show what you mean by way of several example rows?

r937.com | rudy.ca
 
I have:

co_name, id
BigCompany, 1
BigCompany, 2
SmallzCo, 3,
SmallzCo, 4


So, I want to be able to only show BigCompany,1 and SmallzCo,3 from the above data. Meaning, a unique company and the ID associated with it.
 
we're getting warm :)

a unique company and perhaps the lowest id?
Code:
select co_name
     , min(id) as lowest_id
  from user
group
    by co_name

r937.com | rudy.ca
 
R937, this works great, thanks.

 
any books you'd recommend on learning MYSQL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top