本文介绍了如何在asp.net中使用左连接获取单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想通过在asp.net中使用左连接操作从table2获取图像路径。但是没有得到它..所以请帮助我.. 这里我的查询是: Hi, i want to get image path from table2 by using left join operation in asp.net .but didn't get it..so please help me.. here my query is:SELECT n.newsid,n.state,n.district,n.region,n.views,n.currentplace,n.newstitle,n.description,n.poston,n.postby,ni.imagepath,ni.newsid FROM tbl_userpost_news n LEFT JOIN tbl_userpost_newsimages ni ON n.newsid = ni.newsid AND (SELECT TOP 1 * FROM ni WHERE n.newsid=ni.newsid) Order By n.poston desc 请发送当前代码.......谢谢。please send current code for that.......thank you.推荐答案 SELECT n.newsid, n.state, n.district, n.region, n.views, n.currentplace, n.newstitle, n.description, n.poston, n.postby, (SELECT TOP 1 imagepath FROM tbl_userpost_newsimages ni WHERE n.newsid=ni.newsid) AS imagepathFROM tbl_userpost_news nOrder By n.poston desc 注意:我已从select li中删除了 ni.newsid st n.newsid 已经存在并且假设返回相同的值。 希望,它有帮助:)Note: I have removed ni.newsid from select list as n.newsid is already there and suppose to return the same value.Hope, it helps :) SELECT TOP 1 n.newsid,n.state,n.district,n.region,n.views,n.currentplace,n.newstitle,n.description,n.poston,n.postby,ni.imagepath,ni.newsid FROM tbl_userpost_news n LEFT JOIN tbl_userpost_newsimages ni ON n.newsid = ni.newsid ORDER BY n.poston desc它可以工作。 这篇关于如何在asp.net中使用左连接获取单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 09:23