1

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

user3066006
  • 149
  • 1
  • 15
  • [Cross-posted](http://dba.stackexchange.com/questions/140078/selected-child-categories-based-on-parent-categories-from-another-table). Please [do not cross-post](http://meta.stackexchange.com/questions/64068/is-cross-posting-a-question-on-multiple-stack-exchange-sites-permitted-if-the-qu) – Andriy M Jun 01 '16 at 09:00
  • You are saving csv data which is a no-no. And your question is unclear. See the Takeaway at the bottom from my answer [here](http://stackoverflow.com/a/32620163) – Drew Jun 02 '16 at 02:04

0 Answers0