January 13, 2006 at 3:13 am
Hello All,
I'm a bit of an SQL novice so please don't laugh.
I have a database with a load of company names in
Some of these companies do more than one thing (ie. painting and decorating and plumbing) consequently they appear twice in the database.
I want to do a query and extract only unique companies only once
If I use DISTINCT then I think it filters on all of the columns I select
i.e.
SELECT DISTINCT Name, Address, BusinessType, Contact
FROM database
To the best of my knowledge this will qualify a record as distinct if all the columns match (Name, Address, BusinessType, Contact) - am i right?
I want to output all the columns but only check for being DISTINCT on 'Name'
How do you do that?
Thanks in advance.C
January 13, 2006 at 5:28 am
How about something like
SELECT TOP 1 A.[Name], A.Address, A.BusinessType, A.Contact
FROM tblCompanies A
INNER JOIN (SELECT DISTINCT [Name] FROM tblCompanies) B ON A.[Name] = B.[Name]
Hopefully this should get you close
Good Hunting!
AJ Ahrens
webmaster@kritter.net
January 13, 2006 at 5:37 am
Cheers AJ
I'll give it a wirl
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply