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 = [email protected] 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 [email protected] dfgfdhfdhfg fgshhfdfgh fhdfhhfgj
c764cbc3 [email protected] MyName dgsfdhfg fghdfjghj
c764cbc3 [email protected] dgdfgfhfhf dgsdgdf fghfdhfg
f08b9787 [email protected] dfgsdffhhf dfgsdhf fhfhfhf fhfhfh
f08b9787 [email protected] dgsdgdfhfgh dfgshf fhdfhg
f08b9787 [email protected] MyName sdsdgdsgf dfhfhfdg
f08b9787 [email protected] dgsdgfhfdg dgsdfhffh fghdjghj
b1d9dd41 [email protected] dsgdfgd sdgdsgfd fhfdhfg
b1d9dd41 [email protected] MyName dgsdhfdg fghdjgj
e4f9cvd21 [email protected] dgsdfhfdfg dfgshfg fggjgh fghgjg
e4f9cvd21 [email protected] dfgdshfhf dfgdhfg fghdfggjg
Output Result should look like this
**ProductID** **UserEmail** **UserName** **Comments**
c764cbc3 [email protected] dfgfdhfdhfg fgshhfdfgh fhdfhhfgj
c764cbc3 [email protected] dgdfgfhfhf dgsdgdf fghfdhfg
f08b9787 [email protected] dfgsdffhhf dfgsdhf fhfhfhf fhfhfh
f08b9787 [email protected] dgsdgdfhfgh dfgshf fhdfhg
f08b9787 [email protected] dgsdgfhfdg dgsdfhffh fghdjghj
b1d9dd41 [email protected] dsgdfgd sdgdsgfd fhfdhfg