我试图在视图中连接3个表;情况是这样的:

我有一张表格,上面有申请在这所大学校园居住的学生的信息。我有另一个表,列出了每个学生的大厅偏好(其中3个)。但是每个参数都只是一个ID Number,并且ID Number在第三个表中有一个对应的Hall Name(没有设计这个数据库…)。

基本上,我在表中有INNER JOIN和它们的首选项,以及它们的信息,结果是这样的。

 John Doe | 923423 | Incoming Student | 005

005是HallID。所以现在我想把这个HallID匹配到第三个表,这个表包含HallID和HallName。

所以,我希望结果是这样的。

 John Doe | 923423 | Incoming Student | Foley Hall <---(INSTEAD OF 005)

以下是我目前拥有的:

SELECT
  s.StudentID, s.FName, 
  s.LName, s.Gender, s.BirthDate, s.Email, 
  r.HallPref1, r.HallPref2, r.HallPref3
FROM
  dbo.StudentSignUp AS s 
  INNER JOIN RoomSignUp.dbo.Incoming_Applications_Current AS r 
    ON s.StudentID = r.StudentID 
  INNER JOIN HallData.dbo.Halls AS h 
    ON r.HallPref1 = h.HallID

当前回答

select products.product_id, product_name, price, created_at, image_name, categories.category_id, category_name,brands.brand_id, brand_name 
FROM products INNER JOIN categories USING (category_id) INNER JOIN brands USING(brand_id)

其他回答

您只需要第二个内部连接,将您现在拥有的ID Number链接到第三个表的ID Number。然后,将ID Number替换为Hall Name和voilá:)

SELECT column_Name1,column_name2,......
  From tbl_name1,tbl_name2,tbl_name3
  where tbl_name1.column_name = tbl_name2.column_name 
  and tbl_name2.column_name = tbl_name3.column_name
select products.product_id, product_name, price, created_at, image_name, categories.category_id, category_name,brands.brand_id, brand_name 
FROM products INNER JOIN categories USING (category_id) INNER JOIN brands USING(brand_id)
SELECT * 
FROM 
    PersonAddress a, 
    Person b,
    PersonAdmin c
WHERE a.addressid LIKE '97%' 
    AND b.lastname LIKE 'test%'
    AND b.genderid IS NOT NULL
    AND a.partyid = c.partyid 
    AND b.partyid = c.partyid;
select empid,empname,managename,[Management ],cityname  
from employees inner join Managment  
on employees.manageid = Managment.ManageId     
inner join CITY on employees.Cityid=CITY.CityId


id name  managename  managment  cityname
----------------------------------------
1  islam   hamza       it        cairo