私は次のコードを持っています。結合内の選択はそれ自体でうまく機能しますが、結合で機能させようとすると、エラーが発生します。
SQL構文にエラーがあります。1行目のtup.userid = user_id 'のnear'as S)で使用する正しい構文については、MySQLサーバーのバージョンに対応するマニュアルを確認してください。
Select tup.*, tu.email, S.user_id, S.name, S.value
From tb_user_profile tup
join tb_user tu on tup.userid=tu.id
Join((Select tba.id, tba.accountName, tba.currentBalance
from tb_bank_account tba )as T
union
Select tpi.user_id, tpi.name, tpi.value
from tb_property_item tpi )as S) on tup.userid=user_id
私は何が間違っているのですか?次に、上記の構造に他の2つのテーブルを追加する必要があります。
union
;でサブクエリのエイリアスを作成しません。エイリアスを最後に配置します。これを試して:
Select tup.*, tu.email, S.user_id, S.name, S.value
From tb_user_profile tup join
tb_user tu
on tup.userid = tu.id Join
((Select tba.id, tba.accountName, tba.currentBalance
from tb_bank_account tba
) union
(Select tpi.user_id, tpi.name, tpi.value
from tb_property_item tpi
)
) s
on tup.userid = s.user_id ;
ちなみに、重複がないか気にしないことがわかっている場合は、union all
よりも効率的union
です。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加