有四个表表A(设备表) 表B(型号表) 表C(小类别表)表D(大类别表) 关系为A.所属型号ID和B.ID对应
B.所属小类别ID和C.ID对应
C.所属大类别ID和D.ID对应现在想查出某大类下(where D.id = ?)的设备,如何查询?

解决方案 »

  1.   

    select a.* from a,b,c where a.id=b.id and b.cid=c.id and c.did=?
    说明:
    b.cid表示B.所属小类别ID和C.ID对应的那个B表字段
    c.did表示C.所属大类别ID和D.ID对应的那个C表字段
    ?表示你需要的参数
    不需要D表,如果你不需要D表的相关字段的话
      

  2.   

    select distinct D.name 
    from a,b,c,d 
    where a.id=b.id and b.id=c.id and c.id=d.id; 
      

  3.   

    select* from a,b,c,d
    where a.id=b.id and b.id=c.id and c.id=d.id and d.id=?;
      

  4.   

    把他们写的反过来就差不多了,数据量应该是 D>C>B>A