Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:36:24+00:00 2026-06-05T23:36:24+00:00

I have such tables in my database like Customer , Member , Instructor ,

  • 0

I have such tables in my database like Customer, Member, Instructor, Employee etc. Each of these users has his email adrress. I need to check if there is already a user with given email. I was thinking about:

  • Check each table, something like this:
    public bool IsEmailAddressExists(string email)
    {
        if (!Context.Customers.Any(c => string.Equals(c.Email, email, StringComparison.InvariantCultureIgnoreCase)))
            if (!Context.Members.Any(m => string.Equals(m.Email, email, StringComparison.InvariantCultureIgnoreCase)))
              ...
    }
  • Select all emails and check:
    public bool IsEmailAddressExists(string email)
    {
        var emails = Context.Customers.Select(c => c.Email).Union(Context.Members.Select(m => m.Email))...; //other unions
        return emails.Any(e => string.Equals(e, email, StringComparison.InvariantCultureIgnoreCase));
    }

There are more tables and many users, so I would like to know what would be the most efficient way to implement such kind of checking.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:36:26+00:00Added an answer on June 5, 2026 at 11:36 pm

    In pure SQL this would be your most efficient because it stops searching as soon as it hits a match:

    … As a stored procedure:

    CREATE PROCEDURE EmailExists 
        @email varchar(254) = NULL
    AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;
    
        DECLARE @emailExists bit
    
        SET @emailExists = 0
    
        SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Customer WHERE email = @email)
        IF @emailExists = 0
        BEGIN
            SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Member WHERE email = @email)
            IF @emailExists = 0
            BEGIN
                SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Instructor WHERE email = @email)
                IF @emailExists = 0
                BEGIN
                    SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Employee WHERE email = @email)
                END
            END
        END
    
        SELECT @emailExists
    END
    

    … As a scalar-valued function:

    CREATE FUNCTION EmailExists 
    (
        @email varchar(254)
    )
    RETURNS bit
    AS
    BEGIN
        DECLARE @emailExists bit
    
        SET @emailExists = 0
    
        SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Customer WHERE email = @email)
        IF @emailExists = 0
        BEGIN
            SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Member WHERE email = @email)
            IF @emailExists = 0
            BEGIN
                SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Instructor WHERE email = @email)
                IF @emailExists = 0
                BEGIN
                    SELECT @emailExists = 1 WHERE EXISTS(SELECT 1 FROM Employee WHERE email = @email)
                END
            END
        END
    
        -- Return the result of the function
        RETURN @emailExists
    END
    

    In C# with Linq, you can use the Any extension and the || operator. Since Any usually gets translated to EXISTS in SQL and evalutation of the || operator in C# is lazy, evaluation will stop as soon as the first ocurrence of an email is reached.

    bool emailExists = customerEmails.Any(e => string.Equals(e, email, StringComparison.InvariantCultureIgnoreCase))
                       || memberEmails.Any(e => string.Equals(e, email, StringComparison.InvariantCultureIgnoreCase))
                       || instructorEmails.Any(e => string.Equals(e, email, StringComparison.InvariantCultureIgnoreCase))
                       || employeeEmails.Any(e => string.Equals(e, email, StringComparison.InvariantCultureIgnoreCase));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables in my database, for example with such names: TableA, TableB,
OK, I have 3 database tables at the moment: users id: 1, 2 name:
I have my entities such as Customer, Order etc. defined in my Domain Model.
I have a Yahoo! Group that has its own Database tables for various reasons.
I have two tables in my database: (1) PHRASES: t_phrase ======== I like They
Let's say you have three tables named Item, Event, and Seat, constructed as such:
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
I have such code in my JSF template: <h:form> <table id=users cellspacing=0> <a4j:repeat var=person
i have a table with the columns such id, tid, companyid, ttype etc.. the
I'm writing a web app which is used a SaS. Each customer has their

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.