2014-10-17 58 views
0

我有3个表,其中有3个相同的列名到3个表
但第3个表的第3列与第1列不同第二个表列...
我需要将阐明给定的图像和查询... enter image description here如何写3个表的相同列的查询,其中有一个不同的列来执行

//this the query I'm using but not I wanted 
select l.admission_number,l.student_class ,l.student_name ,l.telugu from lkg_to_seventh_marks as l 
union all 
select e.admission_number ,e.student_class ,e.student_name ,e.telugu from eighth_to_ninth_marks as e 
union all 
select t.admission_number ,t.student_class ,t.student_name,t.telugu_1 from tenthclass_marks as t 

回答

0

尝试这样

select l.admission_number,l.student_class ,l.student_name,l.telugu,NULL as telugu_1 
from lkg_to_seventh_marks as l 
union all 
select e.admission_number ,e.student_class ,e.student_name ,e.telugu ,NULL as telungu_1 
from eighth_to_ninth_marks as e 
union all 
select t.admission_number ,t.student_class ,t.student_name,NULL as telugu, t.telugu_1 
from tenthclass_marks as t 

我想你想这个QUER y

select l.admission_number,l.student_class ,l.student_name,cast(l.telugu as char(50)) 
,'NULL' as telugu_1 from lkg_to_seventh_marks as l 
union all 
select e.admission_number ,e.student_class ,e.student_name ,cast(e.telugu as char(50)) 
,'NULL'as telungu_1 
from eighth_to_ninth_marks as e 
union all 
select t.admission_number ,t.student_class ,t.student_name,'NULL'as telugu, 
cast(t.telugu_1 as char(50)) as telungu_1 
rom tenthclass_marks as t 
+0

而不是0值,我们可以得到一个空字符串 – 2014-10-17 09:30:06

+0

我们可以得到一个NULL文本,而不是在空单元0值? 请添加查询,如果你有一个想法 – 2014-10-28 10:05:32

+0

@ShivaDebrown它可以为你或你想改变什么? – Sathish 2014-10-28 10:15:40

0

这可能是有用的。在空单元格

select l.admission_number,l.student_class ,l.student_name,l.telugu,null as telugu_1 from lkg_to_seventh_marks as l union all select e.admission_number ,e.student_class ,e.student_name ,e.telugu ,null as telungu_1 from eighth_to_ninth_marks as e union all select t.admission_number ,t.student_class ,t.student_name,0 as telugu, t.telugu_1 from tenthclass_marks as t 
+0

我想在NULL datagridview单元格中的文本if我使用相同的查询将数据加载到datagridview – 2014-10-28 10:37:27

+0

此查询为前两个表提供空值。 – 2014-10-28 10:46:22

+0

如果我将相同的查询加载到datagridview,那么datagridview单元格将显示空单元格,而不是填充NULL文本。 – 2014-10-28 11:06:58

相关问题