私は2つのテーブルを持っています:
STEP
id
value
SCALE
id
s1
s2
s3
s4
s5
s6
これで、step.id は scale.s1、scale.s2、scale.s3 などの外部キーになり、step から scale.s1-s6 の値を取得したいと考えています。ネストされた選択を使用してこのクエリを作成しました。1回の選択でこの値を取得することは可能ですか?
SELECT (
SELECT step.val FROM step, scale WHERE step.id = scale.s1 AND scale.id = 1) as v1,(
SELECT step.val FROM step,scale WHERE step.id = scale.s2 AND scale.id = 1) as v2, (
SELECT step.val FROM step,scale WHERE step.id = scale.s3 AND scale.id = 1) as v3, (
SELECT step.val FROM step,scale WHERE step.id = scale.s4 AND scale.id = 1) as v4, (
SELECT step.val FROM step,scale WHERE step.id = scale.s5 AND scale.id = 1) as v5, (
SELECT step.val FROM step,scale WHERE step.id = scale.s4 AND scale.id = 1) as v6, (
SELECT step.val FROM step,scale WHERE step.id = scale.s5 AND scale.id = 1) as v7 ;