当前位置: 代码迷 >> Sql Server >> 帮写一条两个表连接的语句,该如何处理
  详细解决方案

帮写一条两个表连接的语句,该如何处理

热度:8   发布时间:2016-04-27 11:13:14.0
帮写一条两个表连接的语句
SQL code
表usermessage(id,username,password,touxiang)和表table20(id,username,title,time,content),其中usermessage和table20中有一共同字段username,现在我想得到这样的结果:显示 表A的username,touxiang,表B的title、time、content ,where条件是根据table20的id来查询,传入的参数是string id4大概代码如下:   string SqlStr4="select username,touxiang,title,time,content from usermessage and table20 where  table20.id='"+id4+"'";


------解决方案--------------------
SQL code
select a.username,a.touxiang,b.title,b.time,b.content from usermessage aleft join table20 b on a.username=b.usernamewhere b.id=
------解决方案--------------------
SQL code
select a.username,a.touxiang,b.title,b.time,b.content from usermessage aleft join table20 b on a.username=b.usernamewhere b.id=
------解决方案--------------------
C# code
string SqlStr4="select a.username,a.touxiang,b.title,b.time,b.content from usermessage a,table20 b where a.username=b.username and b.id='"+id4+"'";
------解决方案--------------------
SQL code
SELECT  a.username ,        a.touxiang ,        b.title ,        b.time ,        b.contentFROM    usermessage a        INNER JOIN table20 b ON A.username = b.usernameWHERE   b.id = @id
------解决方案--------------------
SQL code
select username,touxiang,title,time,content from usermessage a left join table20 b on a.id=b.id and a.username=b.usernamewhere  b.id='"+id4+"'"
  相关解决方案