Query question
-
Hey all, I've got data structured like this: ID - Contact - Company - Email 1 - Jeff - Acme - Jeff@Acme.com 2 - Hester - Acme - Hester@Acme.com 3 - Mort - Acme - Mort@Acme.com 4 - Jason - Widget - Jason@Widget.com 5 - Harriet - Widget - Harriet@Widget.com I need to write a query that will return only the first contact for each company, in this case it should return: ---------------------------------------- 1 - Jeff - Acme - Jeff@Acme.com 4 - Jason - Widget - Jason@Widget.com Thanks in advance! *->>Always working on my game, teach me *->>something new. cout << "dav1d\n";
-
Hey all, I've got data structured like this: ID - Contact - Company - Email 1 - Jeff - Acme - Jeff@Acme.com 2 - Hester - Acme - Hester@Acme.com 3 - Mort - Acme - Mort@Acme.com 4 - Jason - Widget - Jason@Widget.com 5 - Harriet - Widget - Harriet@Widget.com I need to write a query that will return only the first contact for each company, in this case it should return: ---------------------------------------- 1 - Jeff - Acme - Jeff@Acme.com 4 - Jason - Widget - Jason@Widget.com Thanks in advance! *->>Always working on my game, teach me *->>something new. cout << "dav1d\n";
Not Tested but give it a try.
SELECT ID, Contact, Company, Email FROM [table] GROUP BY Company HAVING MAX(ID) = ID
Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970) -
Not Tested but give it a try.
SELECT ID, Contact, Company, Email FROM [table] GROUP BY Company HAVING MAX(ID) = ID
Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970) -
Just a little correction SELECT ID, Contact, Company, Email FROM [table] GROUP BY Company HAVING MIN(ID) = ID
-
Nope:suss: something like select * from [table] t where id=(select min(id) from [table] tt where t.company=tt.company) HTH
-
Hey all, I've got data structured like this: ID - Contact - Company - Email 1 - Jeff - Acme - Jeff@Acme.com 2 - Hester - Acme - Hester@Acme.com 3 - Mort - Acme - Mort@Acme.com 4 - Jason - Widget - Jason@Widget.com 5 - Harriet - Widget - Harriet@Widget.com I need to write a query that will return only the first contact for each company, in this case it should return: ---------------------------------------- 1 - Jeff - Acme - Jeff@Acme.com 4 - Jason - Widget - Jason@Widget.com Thanks in advance! *->>Always working on my game, teach me *->>something new. cout << "dav1d\n";