select Product_ID,Product_Name,Type3_ID from Product where Product.Type3_ID exists(select Type3_ID,Type2_ID from Product_Type3 where Product_Type3.Type2_ID exists(select Type2_ID,Type1_ID form Product_Type2 where Product_Type2.Type1_ID exists(select * from Product_Type1 where Product_Type1.Type1_ID=@type1 ) ) )
这是小弟写的sql语句,但是提示如下错误:关键字 'exists' 附近有语法错误。
关键字 'exists' 附近有语法错误。
'Product_Type2' 附近有语法错误。
')' 附近有语法错误。
            

解决方案 »

  1.   

    declare @type1 intselect Product_ID,Product_Name,Type3_ID from Product 
    where exists
    (select Type3_ID,Type2_ID from Product_Type3 
    where  exists(
    select Type2_ID,Type1_ID from Product_Type2 
    where  exists
    (select * from Product_Type1 where Product_Type1.Type1_ID=@type1 ) ) )
      

  2.   

    好像还是不行啊  人就是报错:
    'Product_Type2' 附近有语法错误。
    ')' 附近有语法错误。 
      

  3.   

    select Product_ID,Product_Name,Type3_ID 
    from Product 
    where Product.Type3_ID 
    in(select Type3_ID from Product_Type3 where Product_Type3.Type2_ID 
    in(select Type2_ID from Product_Type2 where Product_Type2.Type1_ID in (select Type1_ID from Product_Type1 where Product_Type1.Type1_ID=@type1 ) ) )用IN 试试。
      

  4.   

    exists不是这样用的,你的sql写的就不对,仔细学习下exists的用法就懂了
      

  5.   

    首先感谢 shmilywcd的发言,但是好像还是出问题了!!我再介绍一下表的结构吧:
    我有四个表
    Product_Type1 : Type1_ID,Type1_Name
    Product_Type2 : Type2_ID,Type2_Name,Type1_ID
    Product_Type3 : Type3_ID,Type3_Name,Type2_ID
    Product :Product_ID,Product_Name,Type3_ID…   
    我在利用datalist的多层嵌套实现显示第二个表的时候同时等级显示Product表的相关内容,问一下这个sql语句怎么写啊???!@