Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problem with distinct

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-20 : 09:02:09
Natan Levi writes "Hello,

I have one table with id, firstname, lastname, company fields,
i want to get all table information but i want to get only different companies(non duplicate companies).

i try to write "select distinct company, id, firsname, lastname from table" but it not make the results that i want,

Do you have any solution for this problem?

regards,

Natan Levi."

dsdeming

479 Posts

Posted - 2002-08-20 : 12:54:59
If you're getting multiple rows for a company, it must be because the company has rows with different ids, firsnames, or lastnames. If you only want one row per company, you have to tell SQL Server how to deal with those three columns.

SELECT company, MIN( id ), MIN( firstname ), MIN( lastname )
FROM table
GROUP BY company

is one way to do it. It should be enough to get you started.

Go to Top of Page
   

- Advertisement -