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 2005 Forums
 Transact-SQL (2005)
 Query with Three column primary keys

Author  Topic 

mapidea
Posting Yak Master

124 Posts

Posted - 2009-09-05 : 22:33:49
I want to get the list of columns from first table and Subtract that recordset from the second table which match (three columns)


SELECT
tb_video.external_video_thumbnail_url,
tb_video.external_video_processed
FROM
tb_profile_feature_entry tb_entry
INNER JOIN tb_profile_feature_entry_video tb_video on tb_entry.entry_id=tb_video.entry_id
AND tb_entry.feature_id=tb_video.feature_id AND tb_entry.user_id=tb_video.user_id


--Till Here the query is fine

--Now here there are three columns entry_id user_id and feature_id if all the three values match in the tb_entry and tb_profile_feature_entry_vote table that record should not be displyed. How can I modify this query to get the correct result


where tb_entry.entry_id not in(select entry_id from tb_profile_feature_entry_vote where voter_id =@voter_id)

AND
tb_entry.user_id not in(select user_id from tb_profile_feature_entry_vote where voter_id =@voter_id)

AND

tb_entry.feature_id not in(select feature_id from tb_profile_feature_entry_vote
where voter_id =@voter_id)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-06 : 13:53:18
[code]
SELECT
tb_video.external_video_thumbnail_url,
tb_video.external_video_processed
FROM
tb_profile_feature_entry tb_entry
INNER JOIN tb_profile_feature_entry_video tb_video on tb_entry.entry_id=tb_video.entry_id
AND tb_entry.feature_id=tb_video.feature_id
AND tb_entry.user_id=tb_video.user_id
LEFT JOIN tb_profile_feature_entry_vote v
ON tb_entry.entry_id=v.entry_id
AND tb_entry.feature_id=v.feature_id
AND tb_entry.user_id=v.user_id
AND v.voter_id =@voter_id
WHERE v.entry_id is null
[/code]

Go to Top of Page

mapidea
Posting Yak Master

124 Posts

Posted - 2009-09-06 : 14:28:50
Thanks Visakh
Go to Top of Page
   

- Advertisement -