【发布时间】:2017-07-10 21:27:12
【问题描述】:
我创建了 3 个表。 第一个巡回表 第二个 tour_details 表 第三个 tour_img 表
游览表
Create table tour(
id int identity(1,1),
unique_code varchar(10),
tour_name varchar(10)
)
Tour_details 表
Create table tour_details(
id int identity(1,1),
tour_id varchar(10),
description varchar(10)
)
Tour_img 表
Create table tour_img(
id int identity(1,1),
tour_id varchar(10),
img_path varchar(max)
)
现在,我想使用内部连接来连接这三个表,并且只需要 tour_img 表的 1 行
举例
tour table has 1 record
id=1,
unique_code=123456
tour_name= taj mahal
Tour_details
id=1,
tour_id=123456
desc=xyz
Tour_img
id=1,
tour_id=123456
tour_img=taj_01
id=2,
tour_id=123456
tour_img=taj_2
etc...
所以我只想要来自 tour_img 的一条记录
我创建了一个查询,但它不能正常工作。
select a.tour_name,
b.tour_desc,
(
select tour_img
from tour_img
where tour_id='123456'
) as tour_img
from tour a
inner join tour_details b on a.unique_code = b.tour_id
inner join tour_img c on a.unique_code = c.tour_id
where a.unique_code = '123456';
【问题讨论】:
标签: sql asp.net sql-server asp.net-mvc asp.net-mvc-4