我有多个查询想要将所有查询结果合并到同一个表中 [英] I have multiple queries want to merge all query results into the same table

查看:39
本文介绍了我有多个查询想要将所有查询结果合并到同一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

table1:                     table2
studentname                StudentAge   
 stuart                      18  

我有以下查询,例如1)

I have following queries like 1)

select studentname as sname from table1;
  sname
  Stuart

2)

select StudentAge as age from table2;
  age
  18

我想在一个有两列的表中显示查询结果:

I want to display the query results in a table having two columns as:

 category         Values
  sname          Stuart
  age              18

推荐答案

鉴于您提供的数据,每个表中只有一行,您可以使用 CROSS JOIN 将它们连接起来:

Given the data you've presented, with only a single row in each table, you can use a CROSS JOIN to join them:

select t1.studentname, t2.StudentAge
  from table1 t1
  cross join table2 t2

这将执行笛卡尔连接,其中每个表中的每一行都连接到另一个表中的每一行,返回的行数是两个表中行数的乘积.

This will perform a Cartesian join, where each row in each table is joined to every row in the other table, and the number of returned rows is the product of the number of rows in the two tables.

db<>在这里小提琴

这篇关于我有多个查询想要将所有查询结果合并到同一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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