2012-01-17 8 views
2

私は次のクエリを持っている:2つのクエリを結合する方法

クエリ1:

Select * from T10,T11,T12,T13,T14 
where T10.C0 = T11.C0 and T11.C1 = T12.C0 
and T12.C1 = T13.C0 and T13.C1 = T14.C0; 

クエリ2:

Select * from T20,T21,T22,T23,T24 
where T20.C0 = T21.C0 and T21.C1 = T22.C0 
and T22.C1 = T23.C0 and T23.C1 = T24.C0; 

は、どのように私はこれらのテーブルのすべての値を表示するには、これらの2つのクエリを組み合わせることができますか?私は、参加をT10.C1 = T20.C1にしたいと思います。

私が真の同じ列数を、持っていないという警告を取得unionをしようとすると、これらのテーブルは、私が欲しい


組合

ここ
Select * from 
"ProductConfig","Board","PcbBuild","Model","TcssCalib" 
where "Model"."idModel" = "PcbBuild"."Model" and "Board"."PcbBuild" = "PcbBuild"."idPcbBuild" 
and "Board"."idBoard" = "TcssCalib"."Board" and "ProductConfig"."TcssCalib" = "TcssCalib"."idTcssCalib" 

union 

Select * from"ProductBuild","TxResultsLink","TxResults","DspValues" where "ProductBuild"."idProductBuild" 
= "TxResultsLink"."ProductBuild" and "TxResults"."idTxResults" = "TxResultsLink"."TxResults" 
and "TxResults"."DspValues" = "DspValues"."idDspValues"; 

同じではありませんProductBuild.ProductconfigがProductConfig.idProductConfigと結合されました

エラー:

[のErr] ERROR:各UNIONクエリは、私がinner joinをしようとすると、私はで、またはこれらに参加する方法はあり

innerの近くに構文エラーを取得する列


の同じ番号を持つ必要があります2つのクエリを一緒に?

+2

は、移動するための方法です。私たちがデバッグを助けることができるように、あなたのJOINクエリコードを投稿してください。また、これらが難読化された列名であることを願っています。 –

+0

はい、これらは 'テーブルと列の名前を作った(otherwize彼らは私が思うには読めないようになる) – Moonlight

答えて

4

これはあなたが望むものである:、

Select * from T10,T11,T12,T13,T14,T20,T21,T22,T23,T24 
where T10.C0 = T11.C0 and T11.C1 = T12.C0 
and T12.C1 = T13.C0 and T13.C1 = T14.C0 
and T10.C1 = T20.C1 and T20.C0 = T21.C0 and T21.C1 = T22.C0 
and T22.C1 = T23.C0 and T23.C1 = T24.C0; 

とそれを置くために別の、より読みやすい方法で、このようなものです:結果までのUNIONについては

select * from T10 
    inner join T11 on T10.C0 = T11.C0 
    inner join T12 on T11.C1 = T12.C0 
    inner join T13 on T12.C1 = T13.C0 
    inner join T14 on T13.C1 = T14.C0 
    inner join T20 on T10.C1 = T20.C1 
    inner join T21 on T20.C0 = T21.C0 
    inner join T22 on T21.C1 = T22.C0 
    inner join T23 on T22.C1 = T23.C0 
    inner join T24 on T23.C1 = T24.C0; 

、テーブル内のカラム数は同じで、同じ/変換可能なデータ型である必要があります。 A JOINを

Select * from T10,T11,T12,T13,T14 
where T10.C0 = T11.C0 and T11.C1 = T12.C0 
and T12.C1 = T13.C0 and T13.C1 = T14.C0 

UNION 

Select * from T20,T21,T22,T23,T24 
where T20.C0 = T21.C0 and T21.C1 = T22.C0 
and T22.C1 = T23.C0 and T23.C1 = T24.C0; 

Select * from 
"ProductConfig","Board","PcbBuild","Model","TcssCalib","ProductBuild","TxResultsLink","TxResults","DspValues" 
where "Model"."idModel" = "PcbBuild"."Model" and "Board"."PcbBuild" = "PcbBuild"."idPcbBuild" 
and "Board"."idBoard" = "TcssCalib"."Board" and "ProductConfig"."TcssCalib" = "TcssCalib"."idTcssCalib" and "ProductBuild"."idProductBuild" 
= "TxResultsLink"."ProductBuild" and "TxResults"."idTxResults" = "TxResultsLink"."TxResults" 
and "TxResults"."DspValues" = "DspValues"."idDspValues" 
and "ProductBuild"."ProductConfig" = "ProductConfig"."idProductConfig"; 
+0

これは私が欲しいものですが、私は2つのクエリが既に作られている(C#でビルド)これらのクエリを結合する – Moonlight

+0

これを行う適切な方法は、指定したクエリを使用することです。 –

+0

私はあなたの組合のアプローチを試しましたが、それは私の場合にエラーをもたらします(私の編集した質問を参照)。 – Moonlight

関連する問題