表T_Kind K_ID K_Name K_Kind
1 球 0
2 人 0
3 篮球 1
4 足球 1
5 男人 2
5 妖人 2
表T_P P_ID P_Name P_Kind
1 乒乓球 1
2 NBA 3
表T_P的P_Kind和表T_Kind的K_ID 对应。我现在想查出T_P表中根据表T_Kind关联的那2条记录:
SQL code:
--> 测试数据:#T_Kind
if object_id('tempdb.dbo.#T_Kind') is not null drop table #T_Kind
go
create table #T_Kind([K_ID] int,[K_Name] varchar(4),[K_Kind] int)
insert #T_Kind
select 1,'球',0 union all
select 2,'人',0 union all
select 3,'篮球',1 union all
select 4,'足球',1 union all
select 5,'男人',2 union all
select 5,'妖人',2
--> 测试数据:#T_P
if object_id('tempdb.dbo.#T_P') is not null drop table #T_P
go
create table #T_P([P_ID] int,[P_Name] varchar(6),[P_Kind] int)
insert #T_P
select 1,'乒乓球',1 union all
select 2,'NBA',3
--------------------------------查询开始------------------------------
select t.* from #T_Kind t,#T_P p where t.K_ID = p.[P_Kind]
/*
K_ID K_Name K_Kind
----------- ------ -----------
1 球 0
3 篮球 1
(2 行受影响)
*/
是这个意思吗?
sel