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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:19:14+00:00 2026-05-11T15:19:14+00:00

Duplicate: How to do a Select in a Select I have 2 tables: TABLE1

  • 0

Duplicate:

How to do a Select in a Select

I have 2 tables:

TABLE1 Table1Id  TABLE2 Table2Id Table1Id UserId 

TABLE2 has thousands of entries in it. I want to return a list of TABLE1 entries where there isn’t an entry in TABLE2 for it for a particular user. So, where there isn’t a foreign key entry in TABLE2. A query like:

select count(*) from TABLE1 where Table1Id not in ( select Table1Id from TABLE2 where id_user = 1) 

However, that query runs very slowly. What would be the most efficient way of getting the results I require?

  • 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. 2026-05-11T15:19:15+00:00Added an answer on May 11, 2026 at 3:19 pm

    There is a similar question

    I think it would be better

    SELECT COUNT(*)  FROM TABLE1  WHERE NOT EXISTS (SELECT Table1Id FROM TABLE2 WHERE TABLE2.Table1Id = TABLE1.Table1Id AND UserID = 1) 

    I would check the indexes also, as ck suggested

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

Sidebar

Related Questions

Possible Duplicate: jquery: select the last 4 items in the list jQuery has the
I want to remove duplicate rows return from a SELECT Query in Postgres I
Suppose I have 2 tables, each tables has N columns. There are NO duplicate
I have two tables (Table1 and Table2) with the same primary keys, lets say
I currently have the following query SELECT table1.col1, table2.col2 FROM table1 INNER JOIN table2
I have tables like this: Table1 Table2 name1 | link_id name2 | link_id text
Say I have Table1 which has duplicate rows (forget the fact that it has
I have a table say table1(id, col2, col3) , and I want to duplicate
I have 3 tables that join with together and i want select distinct rows
Possible Duplicate: How do I randomly select an item from a list using Python?

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.