私がやろうとしているのは、個人に関するカスタムデータを保持するテーブルをクエリしてフィールドに取得することですが、個々のフィールドをレコードとして取得しています。
私が使用している現在のステートメントは
SELECT s.fname, s.lname, s.email, s.mobile, s.country, cf.name, ca.value FROM
standard AS s
INNER JOIN people AS p ON
(s.pid = p.pid)
INNER JOIN custom_answers AS ca ON
(ca.pid = p.pid)
INNER JOIN custom_fields AS cf ON
(cf.fieldid = ca.fieldid)
WHERE p.acctid = 'xxxxxxxxxx'
これには22,000行の結果セットが与えられますが、私は900行しか探していません。
データ出力の例は次のとおりです。
fname | lname | email | mobile | country | name     | value
tom   | smith | t@t   | 0412   | AU      | state    | Vic
tom   | smith | t@t   | 0412   | AU      | position | Dept Head
tom   | smith | t@t   | 0412   | AU      | guest    | John Smith
mick  | jones | m@j   | 0411   | AU      | postnom  | AOC
mick  | jones | m@j   | 0411   | AU      | state    | NSW
mick  | jones | m@j   | 0411   | AU      | postcode | 2000
一方、出力したいのは
fname | lname | email | mobile | country | state | position  | guest      | postnom | postcode
tom   | smith | t@t   | 0412   | AU      | Vic   | Dept Head | John Smith | null    | null
mick  | jones | m@j   | 0411   | AU      | NSW   | null      | null       | AOC     | 2000
複雑になる場合と引き起こさない場合があるのは、カスタムフィールドの量が各人で同じではないということです。いくつかはほんの一握りまたはカスタムフィールドを持っているかもしれませんが、いくつかは30以上を持っているかもしれません。