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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:34:53+00:00 2026-05-27T18:34:53+00:00

I have multiple tables in my database. Let’s say the table users looks like

  • 0

I have multiple tables in my database. Let’s say the table users looks like this:

Users:
|id|name|gender|access|id_ext|
|1 |  a |  m   |   1  |  32  | 
|3 |  b |  m   |   3  |  33  | 
|4 |  c |  m   |   1  |  34  | 
|5 |  d |  f   |   1  |  35  |

I would like to select the user with for example id_ext = 32 and then run another select statement using that selected users fields.

I can solve this by first getting the user with a query and then create another query with users info, but there must be a way to do this in the same query?

This is the query i use now:

SELECT * FROM users NATURAL JOIN
(SELECT id FROM ages WHERE age BETWEEN
(SELECT limit_age_l FROM users WHERE id=17)
AND (SELECT limit_age_h FROM users WHERE id=17)) as a
WHERE NOT id = 17
AND locale = 'en_US'
AND limit_gender = 1
AND visible = 0
AND NOT EXISTS (SELECT view_id FROM matches WHERE user_id = 17 AND view_id = a.id)
LIMIT 1

Problem is that the values id=17, limit_gender=1 and locale = 'en_US' in the query are not known. These are taken from the user with id_ext = '32'.

  • 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-27T18:34:53+00:00Added an answer on May 27, 2026 at 6:34 pm

    Yes – assuming your subsequnt query is of the form:

    select field1, field2, ...
    from Table1
    join Table2 on ...
    where ...
    and Table1.id = N /* previously selected id from users */
    

    Then either by using the first query as a subquery:

    select field1, field2, ...
    from Table1
    join Table2 on ...
    where ...
    and Table1.id = (select id from users where id_ext ='32')
    /* replace = with IN if more than one id will be returned */
    

    Or by joining to the results of the first query as part of the subsequent query:

    select field1, field2, ...
    from users 
    join Table1 on Table1.id = users.id 
    join Table2 on ...
    where ...
    and users.id_ext ='32'
    

    (Note that both of these forms assume that users is not already being joined in the existing query – if it is, just add the users.id_ext ='32' condition to the existing query.)

    EDIT: If I have understood the requirements correctly, the required query could be written as:

    SELECT u.* 
    FROM users u
    join ages a on u.id = a.id and 
                   u.age between limit_age_l and limit_age_h
    join users ul on ul.id = 17 and 
                     ul.id <> u.id and 
                     ul.locale = u.locale and
                     ul.limit_gender = u.limit_gender and
                     ul.visible = u.visible
    AND NOT EXISTS (SELECT NULL 
                    FROM matches m
                    WHERE m.user_id = ul.user_id AND m.view_id = a.id)
    LIMIT 1
    
    • 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 a data mapper function that aggregates multiple tables and generates
Let's say I have a database with two tables Persons and PhoneNumbers , where
Let's say I have a relational database with tables: OrderableCategories and Orderables. They are
I have some trivial table in database (let say Oracle10g) and I need to
let's say I have three tables (MySQL), one for users, one for tags and
Let's say I have in my database multiple db schema for example : HumanRessources
I have an SQL database with multiple tables, and I am working on creating
I have a MySQL database with multiple tables, each of which have the same
I have a simple database with multiple tables. I can't figure out how to
I have multiple tables with an id component. I'd like to use LINQ to

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.