select a.name,b.description from user a,class b where a.class=b.class 
................ ok?

解决方案 »

  1.   

    select Description from Class where Class.Class=(select Class from User where User.name='你要查找的名字');
      

  2.   

    很好。谢谢。
    我用SQL Builder搞了一回,得出的结果差不多。
    现在想提高点难度:
      1. 如果User表中的Class数字是 Class表中没有的,则显示"未知",上面的SQL语句把
    没有的过滤掉了(纯属讨论,我们的表不会这么愚昧的,呵呵)  2. .......本来我是用Select * from user把所有的字段都显示了的,为了一个class
    的描述,是不是就要“select User.Name,Class.Description ,User.Address,User.Phone...”
    把所有的字段都抄写一遍?多到不多,20多个,但是有没有简便点的法子。如果分不够,说一声,可以加。现在太慢了,问了问题先,再做其他操作 。
      

  3.   

    select * from user a,
    (select a.name,description=isnull((slecet  b.description from class b where b.class=a.class),'未知')
    from user a ) b
    where a.name=b.name
    不过这样用起来并不太好,其实select * 还是少用为好,用到什么就写什么这是很必要的。
    另一种方法用左外联:
    select a.*,description=case b.description when null then '未知’end
    from user a
    left outer join 
    class b
    on a.class=b.class
    显示在Dbgrid时,将class的visible 置为false.