//会员表
id     userName        userPassword
1      u1              u1pwd
2      u2              u2pwd
...//帖子表
id     title           content    userId //将发帖子的用户id保存到这里
1      title1          content1   1
2      title2          content2   1
3      title3          content3   2
4      title4          content4   1
5      title5          content5   2
...
有一个datagrid我想让他显示成这样:
title           content    userName
title1          content1   u1
title2          content2   u1
title3          content3   u2
title4          content4   u1
title5          content5   u2
...这样的话sql语句怎么写?

解决方案 »

  1.   

    SELECT 贴子表.title,贴子表.content,会员表.username,
    FROM dbo.贴子表 INNER JOIN
          dbo.会员表 ON dbo.贴子表.userID = dbo.会员表.ID
      

  2.   

    SELECT 贴子表.title,贴子表.content,会员表.username,
    FROM dbo.贴子表 INNER JOIN dbo.会员表 
    ON dbo.贴子表.userID = dbo.会员表.ID唉,慢了
      

  3.   

    amandag(高歌) ( ) 
    ============
    忙着升星吧,呵呵.
      

  4.   

    string myitem = "a.ID as ID,Cstr(a.Hits) as Main_ID,a.User_ID as User_ID,a.Title as Title,a.Content as Content,a.Add_DateTime as Add_DateTime,a.Edit_DateTime as Edit_DateTime,b.ID as UID,b.User_Sex as User_Sex,b.User_Cent as User_Cent,b.User_NickName as User_NickName,b.User_Res as User_Res,b.User_Date as User_Date";
    string sqlStr = "select "+myitem+" from [main] a,[users] b where a.User_ID=b.User_ID and [email protected]";