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)
 SQL QUERY

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-13 : 06:34:01
Luke writes "I need to pull from email address field with no duplicates.
******************
SELECT DISTINCT dbo.tblDealer.EmailPrimary, dbo.tblDealership.DealershipTypeID, dbo.tblDealer.FirstName, dbo.tblDealer.LastName

FROM dbo.tblDealer INNER JOIN
dbo.tblDealership ON dbo.tblDealer.DealerID = dbo.tblDealership.DealerID

WHERE(dbo.tblDealership.DealershipTypeID = 2) AND (dbo.tblDealer.EmailPrimary > '') ORDER by EmailPrimary ASC
*******************
This works fine but the DISTINCT seems no to work after I add other fields.

I have tried SELECT (DISTINCT (dbo.tblDealer.EmailPrimary)), and others with no success.

I also tried using COUNT only 1 Email Address still no luck.

The next step is to copy these results to another table tblGroup1 and have them update regularly (but a problem for another day)"

nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-13 : 06:54:29
If you want on column to be distinct what do you want to do with the other columns in the resultset?

distinct has to work on the complete row or it doesn't make sense.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-09-13 : 09:55:35
Hack:

SELECT DISTINCT
EmailPrimary
FROM
(SELECT
D.EmailPrimary, DS.DealershipTypeID, D.FirstName
, D.LastName
FROM
tblDealer D
INNER JOIN
tblDealership DS
ON
D.DealerID = DS.DealerID
WHERE
DS.DealershipTypeID = 2
) a


[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -