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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:42:56+00:00 2026-06-06T04:42:56+00:00

How to make this subqueries to good-looking code? And I looking guides about SQL

  • 0

How to make this subqueries to good-looking code? And I looking guides about SQL optimization and code style.

 SELECT foo FROM table WHERE foo_id IN 
    (
    SELECT idchild FROM table2 WHERE idparent IN 
    (SELECT idchild FROM table2 WHERE idparent IN 
    (SELECT idchild FROM table2 WHERE idparent = @id)
    ))
 AND txt_type ='some_cat'
  • 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-06T04:42:59+00:00Added an answer on June 6, 2026 at 4:42 am

    For better performance and readability, do this:

    select t4.foo
    from table2 t1
    join table2 t2 on t2.idparent = t1.idchild
    join table2 t3 on t3.idparent = t2.idchild
    join table t4 on t4.foo_id = t3.idchild and t4.txt_type ='some_cat'
    where t1.idparent = @id
    

    Notice how the first table selected from has an indexed predicate in the where clause. This query will use indexed access all the way through the query and be very efficient.

    Also notice how I moved the predicate for txt_type into the on clause, where it can be applied at the time the row is read, rather than after the joins have been assembled.

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

Sidebar

Related Questions

I'm using MS SQL. I have a huge table with indices to make this
I'm looking for a more efficient way to build this query (double subqueries make
To make this more clear, I'm going to put code samples: $file = fopen('filename.ext',
How can I make this code work? #!/bin/bash ARRAYNAME='FRUITS' FRUITS=( APPLE BANANA ORANGE )
I am trying to make this sample program work (defn foo ([x] (foo x
I want to make this form: echo '<form method=post action=ratinghandler.php style=width: 250px> <input type=hidden
I want to make a MySQL to get daily differential values from a table
I make this code to show and hide p tag depend on the link
I am trying to make this function that extracts text from html for multiple
I have a question about MySQL. I have this table structure: ID Name ------

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.