I have two tables
rules
With three step hierarchy
|id | name | parent | |---|-------|--------| | 1 | A | 0 | | 2 | B | 0 | | 3 | A(1) | 1 | | 4 | A(2) | 1 | | 5 | B(1) | 2 | | 6 | A(1.1)| 3 | | 7 | A(1.2)| 3 | | 8 | A(2.1)| 4 | | 9 | B(1.1)| 5 | | 10| A(3) | 1 |
Subject
|id | date | rules | group | |---|---------------------|-------|-------| | 1 | 2016-05-20 18:24:20 | 2 | AQR48 | | 2 | 2016-05-20 19:31:17 | 5 | AQR52 | | 3 | 2016-05-21 18:11:37 | 6,7,4 | AQR48 |
I need to get second step rules based on group and ruleid(first step) of subject table data
When group = 'AQR48' and rules.parent=1 result should be
|id | name | parent | |---|-------|--------| | 3 | A(1) | 1 | | 4 | A(2) | 1 |
I tried it like this but with out success.
select rules.id,rules.name,rules.parent from rules left join subject on find_in_set(rules.id,subject.rules) where rules.parent=1 AND subject.group='AQR48'
With this I get output as
|id | name | parent | |---|-------|--------| | 4 | A(2) | 1 |
Anyone could help me with this