I have data in below structure.
A
A1 A2
B B1
C C1 C2 C3
These information transferred into two table named group1 and group2.
group1 has first level of data and middle level data.
group2 has last level of data and middle level data.
ie
group1
group_name group_id
A 1
A1 2
B 3
C 4
C1 5
C2 6
group2
group2_name parent_id
A1 1
A2 2
B 1
B1 3
C 1
C1 4
C2 5
C3 6
Now i want to get the last level of information under the group A.
My output could be
group2_name
A2
B1
C3
I can fetch the information level 2 by using below query.
select group2.group_name from group2
inner join
group1 on group1.group_id = group2.parent_id
where group1.group_name = 'A'
How can get the above output?
Here is SQLFIDDLE Demo
Kindly help me.
You could use this:
that returns all elements from table group2 that are not present in table group1.
Or (depending on how your database is structured) also this:
here I am grouping for the first character of the string, and getting the maximum value of the numeric value.