id name relation
1 n1 r1
2 n2 r2
3 n4 r1
4 n5 r1
5 n6 r2
6 n6 r1
the relation relationship of the table is shown above
where the relation field indicates the relationship between the current row and the name fields of other rows. For example, the data of name=n1 and name=n4,name=n5,name=n6 creates a "one-time connection" through R1. The data of name=n2 and name=n6 have a "one-time connection" through R2. N1 and N2, respectively, connect with N2 through R1 and R2, so I will define N1 and N2 as the "secondary connection relationship"
.now I"m going to use sql to find out whether they were in a "secondary connection relationship"
.the sql query written with thinkphp is as follows:
$where["jump_table.name"] = "n1";
$where["land_table.name"] = "n2";
$jump = M("relation")->alias("switch_table")
->join("LEFT JOIN relation AS jump_table ON switch_table.relation = jump_table.relation")
->join("LEFT JOIN relation AS land_table ON switch_table.relation = land_table.relation")
->where($where)
->field("switch_table.name")
->select();
the result of this query is empty.
ask God for advice on how to write this sql.