本帖最后由 wonglaye 于 2009-11-24 14:09:35 编辑

解决方案 »

  1.   

    select * from unit_info u,mem_info m where u.unit_id=m.unit.id
      

  2.   

    select 人名称,单位名称 from unit_info a, mem_info b
    where a.userid=b.userid
      

  3.   

    select * from unit_info a join mem_info b on a.unit_id=b.unit.id
      

  4.   

    select distinct a.人员名称, b.单位名称
    from mem_info a, unit_info b
    where a.关键字 like '%'+b.关键字+'%'
      

  5.   

    我没说明白   
    比如说  某市市直单位有多个姓王的人员   我需要在搜索到每个符合“王”这个人员名称的同时,显示他们的所在单位来进行区分 ,如何写sql 
    谢谢
      

  6.   

    unit_info 表
    unit_id   unit_name
    1          银行
    2          财政
    3          税务
    。mem_info 表
    mem_id   unit_id  mem_name
    1         1        王二
    2         3         李四
    3         2        王五
    4         2        王五
    5         3        张三我需要模糊查询所有姓王的名字全称以及所在单位
      

  7.   

    select mem_info.men_name,unit_info.unit_name from  mem_info m join unit_info u on m.unit_id=u.unit_id where m.mem_name like'王%'
      

  8.   

    select mem_info.men_name,unit_info.unit_name 
    from  mem_info m inner join unit_info u on m.unit_id=u.unit_id 
    where m.mem_name like'王%'
      

  9.   

    INNER JOIN,LEFT OUTER JOIN,RIGHT OUTER JOIN做表连接
      

  10.   


    select distinct a.username, b.unitname
    from mem_info a, unit_info b
    where a.id=b.id and a.name like '%'+b.name+'%'