2016-10-27 9 views
0

どこに問題があるのか​​お手伝いできますか?MYSQL浸透剤より多くのサブクエリ

MYSQLこれは、 "私を返さ" 強いテキスト は、私が検索したい "SQL Serverのサブクエリは複数の値返さ"

Select NameList_name from NameList where NameList.id In 
(Select NameList.id from NameList where id_company = 
(Select company.id From company where company_company Like "XY")) 
And 
(Select id_NameList from NameListGoods where id_NameListGoodsKind = 
(Select NameListGoodsKind.id from NameListGoodsKind where NameListGoodsKind_NameListGoodsKind LIKE "XX")) 
And 
(Select id_NameList from NameListStateFrom where id_StateFrom = 
(Select StateFrom.id from StateFrom where StateFrom_state Like "XXX")) 
And 
(Select id_NameList from NameListStateTo where id_StateTo = 
(Select StateTo.id from StateTo where StateTo_state Like "XYX")); 

:NameListでどこNameList.idから 選択NameList_nameを 正しいNameList.idの透過度 他のサブクエリから返されるもの。

例:

表名前リスト:

ID Name  
1 a 
2 b  
3 c  
4 d  
5 e 

subquery1:

(Select NameList.id from NameList where id_company = 
(Select company.id From company where company_company Like "XY")) 

が私を返します:数字:1,4,5

subquery2:

(Select id_NameList from NameListGoods where id_NameListGoodsKind = 
(Select NameListGoodsKind.id from NameListGoodsKind where NameListGoodsKind_NameListGoodsKind LIKE "XX")) 
は私を返し

:数字2,4,3

subquery3:

(Select id_NameList from NameListStateFrom where id_StateFrom = 
(Select StateFrom.id from StateFrom where StateFrom_state Like "XXX")) 

が私を返します:数字3,4,1

subquery4:

(Select id_NameList from NameListStateTo where id_StateTo = 
(Select StateTo.id from StateTo where StateTo_state Like "XYX")); 
が私を返し

:数字5,4,2,1

ヘッドクエリに

浸透度を、この結果から、私は私の名前リストから名前Namelist.id = 4を表示する必要がある番号4.Thenです;助けのための

Thxを、

+0

ちなみに、SQL(特にMySQLは)のNP問題のこれらの種類を扱うに非常に遅いです。 – Strawberry

+0

クイックフィックス:すべての '='を 'に'に変更する – Shadow

+0

影:すみませんでしたが、結果ist "SQL Server副問合せが1つ以上の値を返しました" –

答えて

1
SELECT a.id 
    FROM (SUBQUERY 1) a 
    JOIN (SUBQUERY 2) b 
    ON b.id = a.id 
    JOIN (SUBQUERY 3) c 
    ON c.id = a.id 
    JOIN (SUBQUERY 4) d 
    ON d.id = a.id; 
関連する問題