mysql - 如何编写一个查询,其中包含3个表相同的列,并执行其中一个不同的列

标签 mysql

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

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

关于mysql - 如何编写一个查询,其中包含3个表相同的列,并执行其中一个不同的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26421788/

相关文章:

mysql - 检查数据库中任何不同表中是否存在记录

php - 了解 session 超时 (php)

php - 在文件中存储大数据与在表中存储大数据

mysql - cakephp 中的表列数

mysql - 了解了有关 SQL 和 no-SQL 的所有知识后,存储树的最佳方式是什么?

mysql - 如何将地址分成多个字段?

针对 REGEXP 的 Mysql 优化

PHP OOP MySQL (WAMP) 变量作用域

mysql - PHPmyadmin 当前日期是否基于我计算机的本地日期?

php - 两个选择到 while 函数