Q:

mysql select query on two tables in specific order

I have two tables  questions table like below 

 and answers table like below

every question has multiple answers
How can I make query to return the result as below table 

A:

You have to order by two columns - q_id and ans_id. Since in question_tb there is no ans_id field you can put 0 instead.
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

