1

我有两个不同的表,Country_mState_m

Table有State字段 like StateId, Name, CountryId, etc,并且CountryTable 有文件 like CountryId, Name, Currency, etc

我想得到一个状态表的数据网格,它应该在其中打印状态名称和相应的国家名称......如何执行这个查询?

4

4 回答 4

4
SELECT S.NAME as STATE_NAME,C.NAME COUNTRY_NAME
FROM STATE_M S JOIN COUNTRY_M C
ON S.COUNTRYID=C.COUNTRYID;
于 2012-12-26T08:40:41.793 回答
3

试试这个

 select s.name as STATENAME,c.name AS COUNTRYNAME from state s 
 inner join country c 
 on s.countryid=c.countryid
于 2012-12-26T08:41:26.003 回答
3
select t1.Name state_name, t2.Name Country_name from State_m t1,Country_m t2 where t1.CountryId=t2.CountryId; 

使用这个

于 2012-12-26T08:41:57.293 回答
1

这是一个连接。首先了解它们可能是个好主意:

http://en.wikipedia.org/wiki/Join_(SQL )

于 2012-12-26T08:42:11.770 回答