如何使用ASP.NET从两个表中获取记录 [英] How to get records from two tables using ASP.NET
问题描述
朋友们,
i有一个问题..那就是我有两张桌子。
1.student 2。attendance
i想要两张桌子的结果..i表示谁在特定日期,团体和批次中缺席。 。
学生桌上有(身份,团体,批次)
考勤表有(身份证,日期)
i希望absentees数据按组和批次和日期排序..请告诉我如何为此编写查询..
我的尝试:
hi friends ,
i have a one problem..that is i have two tables .
1.student 2 .attendance
i want results from two tables ..i mean who's absent on particular date and group and batch..
student tables is haveing (id,group,batch)
attendance table having (id,date)
i want absentees data with sorting by group and batch and date..please tell me how to write a query for that..
What I have tried:
SELECT id,gender,vid,fname,mobino,fathername,date,batch,group,FROM tbl_studentenroll ee WHERE not exists (SELECT vid,date FROM tbl_attendance aa where aa.vid=ee.vid and aa.date='" + ddl_date.SelectedItem.Text + "' and ee.group='" + ddl_group.SelectedItem.Text + "' and ee.batch='" + ddl_batch.SelectedItem.Text + "' );
但它没有排序结果它显示所有组和批次缺席
but it is not sorting results it is shows all groups and batchs absents
推荐答案
SELECT id,gender,vid,fname,mobino,fathername,date,batch,group,FROM tbl_studentenroll ee WHERE not exists (SELECT vid,date FROM tbl_attendance aa where aa.vid=ee.vid and aa.date='" + ddl_date.SelectedItem.Text + "' )
AND
ee.group='" + ddl_group.SelectedItem.Text + "' and ee.batch='" + ddl_batch.SelectedItem.Text + "'
;
我已经更改了原始查询,如下所示:
in not exists子句,我通过删除ee.field引用来改变条件,因为你只从tlb_attendance <中选择br />
我将你的studentroll条件移到了存在检查之外。
I've changed your original query as follows:
in the not exists clause, I changed the condition by removing ee.field references since you're selecting only from tlb_attendance
I moved your studentroll conditions outside of existence check.
这篇关于如何使用ASP.NET从两个表中获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!