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
 SQL Server Development (2000)
 selecting with remove of duplicate items and 3 tables (distinct ?)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-10-29 : 23:42:36
Willi writes "I have some problems with distinct
as example i have 3 tables

company
company_id, name, phone

person
company_id, person_id, first_name, email

Invoice
person_id, date, about

I get a list of all with this code:

select c.company_id, c.name, c.phone, p.pers_id, p.first_name, p.email, i.date, i.about
from company c, person p, invoice i
where c.company_id = p.company_id and p.pers_id = i.pers_id

My Question:

Now I want to know only once each company how was ever have a invoice and the same rows as result

If I use distinct, that don ´t work, because than shows ALL rows that are different in the result

Is there a way to make a distinct only to the first row - company_id to get each company that have an invoice only once, but with the information (rows) to the first matching person and the first matching invoce ?
"
   

- Advertisement -