SQL Query To Select Distinct Value?

Use: SELECT a. Mail_from_user_id AS user FROM TBL_MAIL a WHERE a. Mail_to_user_id = 1 UNION SELECT b.

Mail_to_user_id AS user FROM TBL_MAIL be WHERE b. Mail_from_user_id = 1 UNION will remove duplicates. UNION ALL would not, and be faster for it.

It may be interesting to know if 1-2 and 2-1 is a duplicate for Denis purposes given the fact that in your SELECT this case would not be detected. – Doliveras Feb 21 at 17:37 1 @Doliveras: The OP wants a list of all people, and it's only logical to assume that there should not be duplicates, but that must have been obvious. For that purpose, I believe, 1-2 and 2-1 should be considered duplicates, but this answer will successfully eliminate them with UNION.

– Andriy M Feb 21 at 20:04.

Select mail_to_user_id as mailid from tbl_mail where mail_from_user_id=1 union select mail_from_user_id as mailid from tbl_mail where mail_to_user_id=1 Where 1 is your id. Replace it with desired id.

The DISTINCT, besides the derived table/inline view, is unnecessary because of using UNION. – OMG Ponies Feb 21 at 17:31 yes you are right :) – Vivek Goel Feb 21 at 17:33.

Quick hack: Select idx from (Select mail_from_user_id as idx from tbl_mail where mail_to_user_id = 1 group by mail_from_user_id Union Select mail_to_user_id as idx from tbl_mail where mail_from_user_id = 1 group by mail_to_user_id) group by idx.

Just for an exercise, please click on edit to edit your answer, highlight the part that represents the script and either press Ctrl+K or click { }. The preview will show you the result and you will see for yourself how much more presentable your answer can be. And after you post the edit you'll even earn a badge.

:) – Andriy M Feb 21 at 20:13.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions