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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:47:04+00:00 2026-06-12T11:47:04+00:00

There are two tables, namely LongTable and ShortTable . For example, LongTable looks like:

  • 0

There are two tables, namely LongTable and ShortTable. For example, LongTable looks like:

personA | personB
1 | 2
1 | 3
2 | 4
2 | 5
3 | 4
3 | 5
3 | 6
4 | 5
4 | 6

and ShortTable has the following content:

PersonA
1
2

I wonder how to select records from a LongTable (please note that this table is really long, i.e. about 2.000.000 rows) based on records in the ShortTable. So, the result for this particular case should be:

personA | personB
1 | 2
1 | 3
2 | 4
2 | 5

I started with the following query (but with failure: “Can’t reopen table: ‘ShortTable'”):

SELECT * FROM LongTable
  WHERE
    personA IN (SELECT * FROM ShortTable)
    AND
    personB IN (SELECT * FROM ShortTable)

Code to reproduce temporary tables is given below.

Thanks in advance for any pointer.

CREATE TABLE LongTable (
  personA INT,
  personB INT
);

INSERT INTO LongTable VALUES
(1,2),(1,3),(2,4),
(2,5),(3,4),(3,5),
(3,6),(4,5),(4,6);

CREATE TABLE ShortTable (
  personA INT
);

INSERT INTO ShortTable VALUES
(1),(2);
  • 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-12T11:47:05+00:00Added an answer on June 12, 2026 at 11:47 am

    Try this

     SELECT DISTINCT l.personA, l.personB
     FROM longTable l 
     INNER JOIN ShortTable s ON l.personA  = s.personA 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two tables, categories and books and I'd like to select all books
I have a scenario like this: There are two tables table1 and table2 .
There are two tables Users:Id(PK int), Username(varchar (50)) Emails:Id(PK int), UserId(FK int), Subject(varchar(50)), Content(varchar(250)),
Does anyone have a really good example where there are two tables with a
There are two tables: sales and expenses . sales has two columns: sale_date and
Say there are two tables, Company and Employee. Employee has a foreign key to
Suppose there are two tables. First table, 'user_actions', has two fields: 'user_id' and 'action'.
There are two tables Table 1 select * from manage_tcp; +----+----------+--------+ | id |
There are two tables: CREATE TABLE STORE ( ID INTEGER NOT NULL, MEDICINE_ID INTEGER
There are two tables Table A id column_a 01 abc 01 abc 02 abc

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.