I'm encountering a quite confusing logic right now to query some sort of records. Now, I have a table that have various records associated with their ProductID and UserEmail. I need an exact sql statement to produce the results I need. What I want to do here is to query or fetch sets of records that have ProductIDs associated with the ProductID of that UserEmail and exclude that record with having that particular UserEmail. See for example, I have a table below and I want to fetch all sets of records with ProductIDs that have a UserEmail = myemail@myemail.com and exclude that particular record that has that UserEmail. I tried some statement using join and I ended up of using this statement but would still return null values.
SELECT DISTINCT ProductID,UserEmail,Comments,UserName FROM [ProdCommentsTab]
WHERE NOT EXISTS( SELECT ProductID,UserEmail,Comments,UserName FROM [ProdCommentsTab]
WHERE UserEmail = @useremail)
Table
**ProductID** **UserEmail** **UserName** **Comments**
c764cbc3 ddgdfh43@yahoo.com dfgfdhfdhfg fgshhfdfgh fhdfhhfgj
c764cbc3 myemail@myemail.com MyName dgsfdhfg fghdfjghj
c764cbc3 mitmak84@outlook.com dgdfgfhfhf dgsdgdf fghfdhfg
f08b9787 dgsdhf23@gmail.com dfgsdffhhf dfgsdhf fhfhfhf fhfhfh
f08b9787 dgsdfgf67@yahoo.com dgsdgdfhfgh dfgshf fhdfhg
f08b9787 myemail@myemail.com MyName sdsdgdsgf dfhfhfdg
f08b9787 sdgsdhf@outlook.com dgsdgfhfdg dgsdfhffh fghdjghj
b1d9dd41 dfsfhfgh45@gmail.com dsgdfgd sdgdsgfd fhfdhfg
b1d9dd41 myemail@myemail.com MyName dgsdhfdg fghdjgj
e4f9cvd21 sdfgdfdf@yahoo.com dgsdfhfdfg dfgshfg fggjgh fghgjg
e4f9cvd21 sdfdgdf@gmail.com dfgdshfhf dfgdhfg fghdfggjg
Output Result should look like this
**ProductID** **UserEmail** **UserName** **Comments**
c764cbc3 ddgdfh43@yahoo.com dfgfdhfdhfg fgshhfdfgh fhdfhhfgj
c764cbc3 mitmak84@outlook.com dgdfgfhfhf dgsdgdf fghfdhfg
f08b9787 dgsdhf23@gmail.com dfgsdffhhf dfgsdhf fhfhfhf fhfhfh
f08b9787 dgsdfgf67@yahoo.com dgsdgdfhfgh dfgshf fhdfhg
f08b9787 sdgsdhf@outlook.com dgsdgfhfdg dgsdfhffh fghdjghj
b1d9dd41 dfsfhfgh45@gmail.com dsgdfgd sdgdsgfd fhfdhfg