Obtaining Grandfather and Grandson Table from Father and Son Table

Query to obtain 1st generation and 3rd generation combination based on 2nd and 3rd generation.

Family table

Father | Son

J | K

K | L

M | N

N | O

SELECT m1.Father AS GrandFather, m2.Son AS GrandSon FROM 
Family m1 join family m2 ON m1.son = m2.father;

Result

Grandfather | Grandson

J | L

K | N

M | O

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *