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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:13:45+00:00 2026-06-03T16:13:45+00:00

I have table tree. I have query: SELECT * FROM tree WHERE pid =10

  • 0

I have table “tree”.

I have query: SELECT * FROMtreeWHEREpid=10
This query returns 10 items.

I want to get something like that in result:

id | pid | title | subElements
11 | 10  | t 1   | 12
12 | 10  | t 2   | 16
13 | 10  | t 3   | 0
...

How too build join query to count sub items for this 10 items?

  • 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-03T16:13:47+00:00Added an answer on June 3, 2026 at 4:13 pm

    try this:

    SELECT t1.id, t1.pid, t1.title , count(t2) as subElements FROM tree as t1 
    LEFT JOIN tree as t2 ON t2.pid = t1.id
    WHERE t1.pid=10
    GROUP BY t1.id, t1.pid, t1.title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query with a self join that looks like this, select t1.
I have table with 3 columns A B C. I want to select *
I have a SQL table readings something like: id int client_id int device_id int
I have a table that looks like this: category category_id name category_seo_friendly_url left_id right_id
I have a tree/hierarchy of groups and a SQL table of items,each associated with
I have a MySQL table with a tree data structure. The fields are _id
I have content management system application that uses a polymorphic tree table as the
I have a complex html DOM tree of the following nature: <table> ... <tr>
After creating the parse tree, i have to populate symbol table now. I have
i have table structure with 3 colums (column1, column2, column3) and i want 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.