mysql 同时查两个表
tb1tb2都有字段mid和tim要求是:查这两个表中mid为9的数据,以tim排序SQL语句怎么写,谢谢...
tb1 tb2
都有字段mid和 tim
要求是:查这两个表中mid为9的数据,以tim排序
SQL语句怎么写,谢谢 展开
都有字段mid和 tim
要求是:查这两个表中mid为9的数据,以tim排序
SQL语句怎么写,谢谢 展开
4个回答
展开全部
你是要干什么呢?
要把2个表关联起来查询?
select tbl1.mid,tbl1.tim,tbl2.mid,tb2.tim
from tbl1,tbl2
where tbl1.mid = tbl2.mid
and tbl1.mid = 9
order by tbl1.tim
还是要把2个表的查询结果放到一起?
select mid,tim from tbl1 where mid = 9
union
select mid,tim from tbl2 where mid = 9
order by tim
要把2个表关联起来查询?
select tbl1.mid,tbl1.tim,tbl2.mid,tb2.tim
from tbl1,tbl2
where tbl1.mid = tbl2.mid
and tbl1.mid = 9
order by tbl1.tim
还是要把2个表的查询结果放到一起?
select mid,tim from tbl1 where mid = 9
union
select mid,tim from tbl2 where mid = 9
order by tim
展开全部
建议采用联合查询 join 而且使用全连接(FULL JOIN)方式
select *
from web_pian
FULL JOIN Orders
ON web_pian.mingcheng=web_shang.mingcheng
Order by web_pian.mingcheng
解释下:FULL Join 全连接将会输出所有的记录,即使有些空缺,和Left Join 左连接有所不同
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-02
展开全部
select *
from tb1 as tbl1,tb2 as tbl2
where tbl1.mid = tbl2.mid
and tbl1.tim = tbl2.tim
and tbl1.mid = 9
order by tbl2.tim
from tb1 as tbl1,tb2 as tbl2
where tbl1.mid = tbl2.mid
and tbl1.tim = tbl2.tim
and tbl1.mid = 9
order by tbl2.tim
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-02
展开全部
不知道你的两个表是否是有关联的,,,
select *
from
(select mid,tim
from tb1
where mid=9
union all
select mid,tim
from tb2
where mid=9)
order by tim
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询