如何编写 3 个表相同列的查询,其中一个不同的列要执行 [英] How to write a query of 3 tables same columns and among them one different column to execute

查看:31
本文介绍了如何编写 3 个表相同列的查询,其中一个不同的列要执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个表,其中有 3 个相同的列名到 3 个表
但是第三个表的第三个列与第一个第二个表列不同..
我的需要将澄清给定的图像和查询...

I have 3 tables,among them there are 3 same column names to 3 tables
but the 3rd table has 3rd column is different to first second table columns..
My need will clarify given image and query...

//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

推荐答案

试试这个

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

我想你想要这个查询

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

这篇关于如何编写 3 个表相同列的查询,其中一个不同的列要执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆