0

MySQL has 2 tables with the same rows.

Table 1 Table 2

For an edit I need one TreeList without true leafs and edit the true leafs separately in a Grid and for the Employees i need one TreeList with the true leafs.

It look like this: For Work

How can I create MySQL query to make sure I can use two separate tables as a one?

The simple way to show the Tree is this query:

 $sql =  'SELECT * FROM '.TP.'lv_tree AS lvtree '.
         'WHERE lvtree.parentId = ?';

    $result = $db->connect()->prepare($sql);
    $result->bindParam(1, $_REQUEST['node']);   

    $result->execute();   

I have already tried JOIN, LEFT JOIN, etc., but to no avail.

3
  • 1
    Does nobody have at least an idea? Commented Aug 20 at 6:19
  • 1
    Try SQL UNION: ` 'SELECT * FROM '.TP.'lv_tree AS lvtree '. 'WHERE lvtree.parentId = ? UNION SELECT * FROM '.TP.'lv_tree AS lvtree2 ' 'WHERE lvtree.parentId = ?'; Commented Aug 20 at 12:46
  • For the edit: if you are going to edit leaf by leaf, you can do it in the tree without any need to bind it to a grid. Commented Aug 20 at 12:48

1 Answer 1

0

my example assume both in one table . if wrong just modify

select
*
from
(
    select  
        * 
    from 
        lvtree 
    where 
        parent_id = 0 and leaf = false
) as A
left outer join (
    select  
        * 
    from 
        lvtree 
    where 
        parent_id <> 0 and leaf = false
) as B
    ON B.parent_id = A.id
left outer join (
    select  
        * 
    from 
        lvtree 
    where 
        parent_id <> 0 and leaf = true
) as C
    ON C.parent_id = B.id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.