【发布时间】:2013-12-06 07:12:10
【问题描述】:
我有 2 个查询将 2 个结果复制为:
结果 1:
select title1,age1 from tab1 where title1 in ('1','2')
title1 age1
1 2
2 3
结果 2:
select title2,age2 from tab2 where title2 in ('a','c')
title2 age2
a b
c d
我希望我的结果简单地并排连接在一起作为最终结果:
title1 age1 title2 age2
1 2 a b
2 3 c d
如何以简单的方式实现这一目标?我搜索了但没有找到解决方案。
== 更新表的架构
+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| title1 | int(11) | YES | | NULL | |
| age1 | int(11) | YES | | NULL | |
+--------+---------+------+-----+---------+-------+
2 rows in set (0.01 sec)
mysql> describe tab2;
+--------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------+------+-----+---------+-------+
| title2 | varchar(2) | YES | | NULL | |
| age2 | varchar(2) | YES | | NULL | |
+--------+------------+------+-----+---------+-------+
=== 更新: 我尝试了以下操作:
select * from
(select title1, age1 from tab1 order by title1,age1) as result1 ,
(select title2, age2 from tab2 order by title2,age2) as result2 ;
它产生了 4 行:
+--------+------+--------+------+
| title1 | age1 | title2 | age2 |
+--------+------+--------+------+
| 1 | 2 | a | b |
| 2 | 3 | a | b |
| 1 | 2 | c | d |
| 2 | 3 | c | d |
+--------+------+--------+------+
【问题讨论】:
-
欢迎来到 Stack Overflow!请edit您的问题包含您的查询代码。
-
发布您的表架构。什么是关系列(如果有)?
-
子查询中无限制的顺序没有意义,任何顺序都是巧合。