表A
id               name          
1                     a
2                     b
3                     c表B
id           p             pid
1            5               1
2            6               1
3            7               1
4            5               2
5            6               2
6            9               2
7            5               3关联表A  B  现在要查询满足p=5  p=6  的name
查询语句该怎么写   

解决方案 »

  1.   

    select A.name from A ,B where A.id=B.id and B.p in(5,6)
      

  2.   


    select name from A,B where A.id=B.id and B.p in(5,6);
      

  3.   

    Quote: 引用 2 楼 fdipzone 的回复:

    [code=sql]
    select name from A,B where A.id=B.id and B.p in(5,6);
    我想得到的结果只是a 和b   这个查询好像得出的是a a  b b
      

  4.   


    select A.name from A ,B where A.id=B.id and B.p in(5,6);
    得出就是a,b,除非你的数据与你给出的不同
      

  5.   

         a.id=b.pid   应该是这个
      

  6.   


    select a.name from a ,b where a.id=b.pid and B.p in(5,6) group by a.name