怎样实现这样的数据查找:
Table1: ZB_ID, Accept_ID ,Area (Zb_ID 为主键)
table2: KF_ID ,Accept_ID, City ,Remark (Accept_ID 为主键)
在Table1 中选出符合其所有Accept_ID 中 City=北京的记录
你可以有两种方法:
1。 建立一个试图,将两个表连接在一起,这样就像一个表那样用
2。 不用试图,完全编写sql
select Table1.ZB_ID, Table1.Accept_ID ,Table1.Area,
table2.KF_ID, table2.City ,table2.Remark
from table1 left join table2 on (Table1.Accept_ID=Table2.Accept_ID )
where table2.City=北京
select * from table1 where Accept_ID in (select Accept_ID from table2 where City=北京)