Sql语句查询问题?
有两张表,act_type和act_nextType里存的都是type_id值,我想查询出对应的名称,应该怎么写?
CREATE TABLE [dbo].[t_Activity] (
[Act_ID] [int] IDENTITY (1, 1) NOT NULL ,
[Act_Type] [int] NULL ,
[Act_NextType] [int] NULL ) ON [PRIMARY]
GO
CREATE TABLE [dbo].[t_ActivityType] (
[Type_ID] [int] IDENTITY (1, 1) NOT NULL ,
[Type_Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
请指点,谢谢!
------解决方案--------------------select Type_Name,t_Activity.*
from
t_ActivityType inner join t_Activity on t_ActivityType.Type_ID=t_Activity.Act_Type
------解决方案--------------------select t_Activity.*,(select type_name from t_activitytype where type_id=t_Activity.Act_type) as act_typename,(select type_name from t_activitytype where type_id=t_Activity.Act_nexttype) as act_nextypename from t_activity
------解决方案--------------------select Type_Name from t_ActivityType where Type_ID=?
输出 id--name