0

私はほぼ正しいSQLクエリを持っていますが、ユーザーがデータベースに複数の航空機を持っている場合、返された結果に複数の行のリストが表示されます:

SELECT  a.this_pay, 
    u.username, 
    u.user_id, 
    c.type_id,
    c.is_primary, 
    x.typename, 
    p.pf_city, 
    p.pf_state, 
    n.username AS non_username, 
    n.user_id AS non_user_id, 
    n.pf_city AS non_pf_city, 
    n.pf_state AS non_pf_state 
    FROM (((((jowner_event_attendees a 
    LEFT JOIN jowner_users u ON a.user_id = u.user_id) 
    LEFT JOIN jowner_aircraft c ON a.user_id = c.user_id) 
    LEFT JOIN jowner_aircraft_types x ON x.id = c.type_id) 
    LEFT JOIN jowner_profile_fields_data p ON a.user_id = p.user_id) 
    LEFT JOIN jowner_not_users n ON a.user_id = n.user_id) 
    WHERE a.event_id = 28 ORDER BY COALESCE(u.username,non_username);

複数の航空機を持っている人の複数のエントリを持つリストになってしまいます。「jowner_aircraft」テーブルに航空機のエントリがいくつあっても、1 つのエントリだけを返したいと思います。

また、アプリの他の部分が依存しているため、このクエリを大幅に変更したくないと思います。明らかに、私が求めている改訂が必要ですが、完全に書き直さずに回答してください。

4

3 に答える 3