Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下のような2つのテーブルの質問テーブルと、以下のよう な回答テーブルがあります。 すべての質問には複数の回答があります。次の表のよう に結果を返すクエリを作成するにはどうすればよいですか
との 2 つの列で並べ替える必要がq_idありans_idます。inquestion_tbにはans_idフィールドがないため、0代わりに配置できます。
q_id
ans_id
question_tb
0
select t.id, t.q_content from ( select q_id, q_content, 0 k, q_id id from question_tb union select ans_q_id, ans_content, ans_id, ans_id from answer_tb ) t order by t.q_id, t.k