October 4, 2007 at 11:48 am
I've searched here and a few other places but can't find syntax that will help me find find records that match on one column but not on another.
This is my most recent effort:
Select *
From History
Where DialID = DialID
and exists (Select *
From History
Where ProjectID <> ProjectID)
I've also tried something simpler such as this:
SELECT top 100 *
FROM History
WHERE DialID = DialID
AND ProjectID <> ProjectID
October 4, 2007 at 11:59 am
Select *
From History
Where ProjectID <> ProjectID
I'm assuming one of these "ProjectID" fields resides in a different table?????
The above statement will never return a record because ProjectId will always ProjectID.
What is the criteria of what the statement should exclude?
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgOctober 4, 2007 at 12:04 pm
The data is all in the same table and what I'm looking to return are all records from one table where the ProjectID is different and the DialID is the same.
October 4, 2007 at 12:20 pm
So are there only duplicates in the table or can there be triplicates, quad's etc...?
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgOctober 4, 2007 at 12:21 pm
October 4, 2007 at 12:26 pm
CREATE TABLE #test (dialId INT, projectId INT)
INSERT #test
SELECT 1,1 UNION ALL
SELECT 1,1 UNION ALL
SELECT 1,1 UNION ALL
SELECT 1,1 UNION ALL
SELECT 2,5 UNION ALL
SELECT 2,5 UNION ALL
SELECT 2,6 UNION ALL
SELECT 2,7 UNION ALL
SELECT 3,2 UNION ALL
SELECT 3,2
SELECT
t1.*
FROM
#test t1
INNER JOIN (SELECT t2.dialId, COUNT(DISTINCT t2.projectId) AS idCount FROM #test t2 GROUP BY dialID) t3
ON t1.dialID = t3.dialID
AND t3.idCount > 1
DROP TABLE #test
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgOctober 4, 2007 at 12:29 pm
mrpolecat (10/4/2007)
Select t1.*From History t1
join history t2
on t1.DialID = t2.DialID and
t1.ProjectID <> t2.ProjectID
Close, but results in a cartesian product.
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgOctober 4, 2007 at 12:51 pm
October 4, 2007 at 1:03 pm
Ron, got you message. I would use what Jason has suggested here. Give me a call if you need to discuss further. BTW, I got your e-mail and I am not in a place to look at your server. Give me a call if you need to; otherwise, I can look into this tonight or tomorrow as I will be working from my home office.
October 4, 2007 at 1:15 pm
Thanks to all, this helped me get something usable.
John, I'll cc you on an email regarding this issue and will call do discuss.
Thanks again!
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply