Results 1 to 6 of 6

Thread: Distinct ++

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question Distinct ++

    Hello,

    I have a situation with SQL query. I have the following 2 tables.

    Table 1
    Name Email
    aa [email protected]
    bb [email protected]
    cc [email protected]
    dd [email protected]
    ee [email protected]
    bb [email protected]

    Table 2
    Name Email
    bb [email protected]
    dd [email protected]

    Now I wish to eliminate the common emails of Table 2 from Table 1 and send email to the rest of the person. This means emails are going to aa, bb (last person), cc and ee. I am trying to use DISTINCT keyword with email and getting success. But along with the email I want to get the names of the corresponding persons. I wish to get distinct emails and their corresponding names and send a common emails to each of them. I need to know the sql query to overcome the situation.

    Please help. Thank you so much.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Distinct ++

    Do you mean the exact email address or just part of the email address such as: gmail or com, etc?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Exclamation Re: Distinct ++

    Quote Originally Posted by Nightwalker83
    Do you mean the exact email address or just part of the email address such as: gmail or com, etc?
    I wish to get the following result.

    Name Email
    aa [email protected]
    cc [email protected]
    ee [email protected]
    bb [email protected]

    Please help.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Distinct ++

    select email from table1
    union select email from table2
    group by email
    having count(email) = 1
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Distinct ++

    select name, email from table1 where table1.email not in (select email from table2);

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Distinct ++

    Better:

    select distinct name, email from table1
    left join table2 r using (name, email)
    where r.name is null


    Of course, this all assumes you're using MySQL. If you're using T-SQL, it is even simpler:

    select name, email from table1
    minus
    select name, email from table2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width