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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:53:25+00:00 2026-06-15T11:53:25+00:00

I have two query 1) tree and 2) units first query SELECT * FROM

  • 0

I have two query
1) tree and 2) units

first query

SELECT * FROM tree WHERE entity_id = 8656 

return below data:

entity id | parent_id | length
-------------------------------
8656      | 8656      | 0
8656      | 8655      | 1
8656      | 8654      | 2
8656      | 8653      | 3
8656      | 4331      | 4
8656      | 2         | 5
8656      | 1         | 6

second query

SELECT * FROM units WHERE activity_id =10066

returns

id  | activity_id | activity_name | region_id | region_name 
-----------------------------------------------------------
136 | 10066       | Cricket       | 4331      | Yote
137 | 10066       | Cricket       | 8653      | Handbreath
140 | 10066       | Cricket       | 8656      | Kevb

result expected

    entity id | parent_id | length | region_name
    --------------------------------------------
    8656      | 8656      | 0      | Kevb
    8656      | 8655      | 1      | null
    8656      | 8654      | 2      | null
    8656      | 8653      | 3      | Handbreath
    8656      | 4331      | 4      | Yote
    8656      | 2         | 5      | null
    8656      | 1         | 6      | null

I have tried this query

SELECT tree . * , units.region_name
FROM tree
LEFT JOIN units ON tree.parent_id = units.region_id
WHERE tree.entity_id = 8656
AND units.activity_id = 10066
  • 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-15T11:53:26+00:00Added an answer on June 15, 2026 at 11:53 am

    By moving the u.activity_id =10066 to the LEFT JOIN and not the WHERE clause, I am able to produce the result:

    select t.entity_id,
      t.parent_id,
      t.length,
      u.region_name
    from tree t
    left join units u
      on t.parent_id = u.region_id
      and u.activity_id =10066
    WHERE t.entity_id = 8656 
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

I have two MySQL queries QUERY: SELECT sodnik_1 FROM prihodnji_krog WHERE file_id='8778' AND sodnik_1
I have two tables that I am joining with the following query... select *
I have two tables described below. What I need is a single query that
i have a problem concerning a select query in MYSQL i have two different
I am using Entity framework on a forum website and have two query examples
I have two different tables, lead and click. I would like to query MySQL
I have two tables in my database table1, table2. I have a join query
So I have two tables students (PK sID) and mentors (PK pID). This query
I'm having some problems trying to perform a query. I have two tables, one
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb

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.