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

  • Home
  • SEARCH
  • 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 8721357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:12:30+00:00 2026-06-13T07:12:30+00:00

I have a query say, select col1,col2 from table1; which return 2 columns of

  • 0

I have a query say,

select col1,col2 from table1;

which return 2 columns of multiple rows. I want to use these two values in where condition of another query. Something like

select col3,col4 from table2 where col5=col1 and col6=col2;

where col1 and col2 are the resultant values of the first query.

Currently I have used inner query something like

select col3,col4 from table2 
where col5 in (select col1 from table1) 
  and col6 in (select col2 from table1);

But I dont want to use inner query like the one shown above as it slows down bring results.

Please suggest.

  • 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-13T07:12:31+00:00Added an answer on June 13, 2026 at 7:12 am

    JOIN them instead of using IN‘s like so:

    SELECT t2.col3, t2.col4 
    FROM table2 t2
    INNER JOIN
    (
       SELECT col1, col2 
       FROM table1
    ) t1 ON t2.col5 = t1.col1 AND t2.col6 = t1.col2
    

    Note that, you didn’t need to select specific columns in the second table. You can JOIN the second table table1 directly like so:

    SELECT t2.col3, t2.col4 
    FROM table2 t2
    INNER JOIN table1 t1 ON  t2.col5 = t1.col1 
                         AND t2.col6 = t1.col2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this query: select * from table1 r where r.x =
Say I have this query: SELECT name::text, id::int, pass:bool FROM mytable; which gives me
So lets say i have a query like this SELECT a as d,b,c FROM
Let's say I have this query, SELECT T.A FROM T WHERE T.A IN (CASE
Let's say I have something like this: $db=new PDO($dsn); $statement=$db->query('Select * from foo'); while
I have a query, say Select foo from bar Foo is a string field,
say if I have the query select users.user_id, users.fname, users.lname, bios.bio, groups.groupid from users
Let's say I have a query like this: SELECT * FROM table_name WHERE venue
lets say I have a table called table1 and it's corresponding columns are col1,
Let's say you have a view: CREATE VIEW dbo.v_SomeJoinedTables AS SELECT a.date, a.Col1, b.Col2,

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.