使用子查询时从另一个表中获取名称

时间:2015-06-14 08:41:31

标签: sql-server sql-server-2008

我有这样的查询:

select 
    F_ExhibitionCode,
    F_ExhibitorCode 
from 
    T_ExhibitorLocation 
where 
    F_ExhibitorCode in (
        select 
            F_Exhibitor_Code 
        from 
            T_Exhibitor 
        where 
            F_Exhibitor_Name  LIKE '%''%')

我还有两个表,一个是* T_Exhibition *,另一个是“T_Exhibitor,F_exhibiton名称来自T_ExhibitionF_ExhibitorCode来自T_Exhibitor
最终结果我需要这样: F_Exhibitonnaem,F_E​​xhibition代码,F_exibitorname,F参展商代码。

1 个答案:

答案 0 :(得分:3)

假设我理解你的表结构,我会建议这些内容:

SELECT EL.F_ExhibitionCode, EL.F_ExhibitorCode, E.F_exhibiton_name
FROM T_ExhibitorLocation EL
INNER JOIN T_Exhibitor E ON(EL.F_ExhibitorCode = E.F_ExhibitorCode)
WHERE E.F_Exhibitor_Name LIKE '%''%'