各位高手你们好:请帮帮小弟,是这样的 我有两个表 分别是 A表 和 B表 结构如下
A表:
code tm
=================
001 123
002 112
003 119 B表:
code tm
==================
208 119
300 623
302 325 我得的结果是(意思是 在A、B表里面 同时找出字段为tm=“119”的所有记录 )请问SQL语句是什么写?
code tm
=============
003 119
208 119
A表:
code tm
=================
001 123
002 112
003 119 B表:
code tm
==================
208 119
300 623
302 325 我得的结果是(意思是 在A、B表里面 同时找出字段为tm=“119”的所有记录 )请问SQL语句是什么写?
code tm
=============
003 119
208 119
union all
select code,tm from B where tm='119'
where tm='119'
union all
select * from B
where tm='119'
select code,tm from
(
select code,tm from A
union all
select code,tm from B)
t where tm='119'
CREATE TABLE [A]
(
code varchar(20),
tm varchar(20)
)
INSERT [A]
SELECT '001','123' UNION all
SELECT '002','112' UNION all
SELECT '003','119'GOif OBJECT_ID('[B]') is not null DROP TABLE [B]
CREATE TABLE [B]
(
code varchar(20),
tm varchar(20)
)
INSERT [B]
SELECT '208','119' UNION all
SELECT '300','623' UNION all
SELECT '302','325'
select * from A where tm='119'
union all
select * from B where tm='119'-------------------------------运行效果---------code tm
-------------------- --------------------
003 119
208 119
union all
select * from B where tm in (select tm from A)
select *from (
select code,tm from A
union all
select code,tm from B ) A
where tm='119'
where tm='119'
union all
select * from B
where tm='119'