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 242243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:49:16+00:00 2026-05-11T20:49:16+00:00

so let’s say i’m building this contact management system. There is a USER table

  • 0

so let’s say i’m building this contact management system. There is a USER table and a CONTACT_INFO table.
For every USER, I can have zero or more CONTACT_INFO records. The way I’ve defined it, I’ve setup a foreign key in my CONTACT_INFO table to point to the relevant USER record.

I would like do a search for all the USER records that do not have CONTACT_INFO records.

I expect that this could be done:

SELECT * FROM user u WHERE u.user_id NOT IN (SELECT DISTINCT c.user_id FROM CONTACT_INFO);

My concern is that as the tables grow, this query’s performance can degrade significantly.

One idea I’m playing with is to add a column in the USER table that says if it has any CONTACT_INFO records or not. Also, I was wondering, if upon inserting any record into CONTACT_INFO, the DBMS has to verify that the record exists, it would already be accessing that record for the sake of verification and so updating it, when I update a CONTACT_INFO record should not be that costly, performance-wise.

As always, feedback is appreciated.

  • 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-05-11T20:49:16+00:00Added an answer on May 11, 2026 at 8:49 pm

    From my tests, the following is faster than BradC’s method:

    select (...)
    from user u
    where not exists (select null from CONTACT_INFO c where u.user_id = c.user_id)
    

    This may be because the compiler does have to do the conversion itself, I don’t know.

    Le Dorfier is correct in principle, though: if you have set up your indexes right on the database (i.e. both user_id columns should be indexed), both your answer and most of these responses here will be extremely fast, regardless of how many records you have in your database.

    Incidentally, if you’re looking for a way to get a query that lists users along with a “HasContactInfo” boolean value, you could do something like this:

    select u.(...), 
      (case when exists (select null from CONTACT_INFO c where c.user_id = u.user_id) then 1
            else null
            end) has_contact_info
    from user u
    

    This second solution may not be useful in your case, but I found it to be much faster than some simpler queries that I had assumed would get optimized automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Given your previous question, you're generating this string as part… May 12, 2026 at 12:37 am
  • Editorial Team
    Editorial Team added an answer rvec.resize(Max); for (int i = 0; i < Max; ++i)… May 12, 2026 at 12:37 am
  • Editorial Team
    Editorial Team added an answer In previous versions of IE, its not possible to register… May 12, 2026 at 12:37 am

Related Questions

So let's say I have two different functions. One is a part of the
So let's say we have a domain object such as the following public class
So let's say I'm using Python 2.5's built-in default sqlite3 and I have a
So let's say I wanna make a dictionary. We'll call it d . But
So let's say that I have a database for managing customers. A customer has

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.