求一段从两表中查数据的SQL语句

来源:百度知道 编辑:UC知道 时间:2024/06/28 04:14:28
table1:
Tname no TArea FFF 地区=CC No相同
A 1 CC 5 * *
B 3 FF 2
D 2 CC 1 * *

table2:
Aname no AArea FFF 名=FF
ff 2 OE 1 * *
KJ 2 IE 2
ff 3 if 8 *
ff 3 P 9 *
ff 1 Ps 7 * *

我想得到:

1. table1 中 TArea 为 CC 的数据;
如上表:

2. Tabel2 中 Aname 为 ff 的数据;

3. 最后找出 1,2 中 No 相同的数据,得到这些数据里所有的FFF.

如上表,最后查出的数据应该是(上表两*的FFF):

FFF: 5 1 7

我想问的就是,可不可以只用SQL语句实现??如果该SQL语句不比本段文字
行数多很多的话,那它对我非常有用!!

我是要用VC++做小系统,里面有类似的查询.

我就是认为如果第一二步查询的结果就用结构体数据来保存的话,太浪费空间了,
如果有更好的方法,不全用SQL语句也行!!请帮帮忙^_^!!
我在Txt文件中写出来的,在这排版就不对了,发张图看看

*******************************
1、table1 中 TArea 为 CC 的数据
select * from table1 where TArea = 'CC';

*******************************
2、Tabel2 中 Aname 为 ff 的数据
select * from Tabel2 where Aname = 'ff';

*******************************
如果你的目的是只要第三步结果的话,直接使用下面这个:

3、最后找出 1,2 中 No 相同的数据,得到这些数据里所有的FFF
select a.fff from
(select * from table1 where TArea = 'CC') a,
(select * from Tabel2 where Aname = 'ff') b
where a.No = b.No
union
select b.fff from
(select * from table1 where TArea = 'CC') a,
(select * from Tabel2 where Aname = 'ff') b
where a.No = b.No;

---
以上,希望对你有所帮助。

select TArea from table1 where Tarea='cc'
select Tname from table2 where Tname='ff'

select * from table1 where no in(select no from table2 where Aname='ff')

汗~~~~~~

这么简单的都要提问......
你数据库中要找的字段数据