This question already has answers here:
How to create a MySQL hierarchical recursive query
                                
                                    (15个答案)
                                
                        
                                去年关闭。
            
                    
我在MySql数据库中有下表:

mysql - 在MySql中检索连接的行-LMLPHP

我需要找出所有连接的行,无论在club_case_sno列中是否存在case_sno。

例如,如果某人搜索case_sno = 10,则应检索以下结果:

mysql - 在MySql中检索连接的行-LMLPHP

我需要执行上述操作的sql查询。

最佳答案

可以尝试:

SELECT * FORM tbl_sno WHERE (club_case_sno = 10
OR case_sno IN
 ( SELECT club_case_sno FROM tbl_sno WHERE case_sno = 10)
OR club_case_sno IN
 ( SELECT club_case_sno FROM tbl_sno WHERE case_sno = 10))
AND is_connected = 1

08-25 10:57