mysql 同时查两个表

2024-12-27 05:29:35
推荐回答(4个)
回答1:

你是要干什么呢?
要把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:

建议采用联合查询 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 左连接有所不同

回答3:

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

回答4:

不知道你的两个表是否是有关联的,,,

select *
from 
(select mid,tim
from tb1
where mid=9
union all
select mid,tim
from tb2
where mid=9)
order by tim