-1

我有这个查询:

SELECT 
  CONCAT(users.id, '#_#', users.nickname, '#_#', users.avatar, '#_#',
         questions.datetime,'#_#',questions.question,'#_#',0000) as summary
FROM
  `questions` join users
  on users.id = questions.id_user 
WHERE
  questions.id = 12 
UNION 
SELECT
  CONCAT(users.id, '#_#', users.nickname, '#_#', users.avatar, '#_#',
         answers.datetime,'#_#',answers.answer,'#_#',answers.id) as summary 
FROM
  answers join users
  on users.id = answers.id_user where id_question = 12

此查询必须包含一列(带有连接数据),我需要按 answers.datetime 排序,但我自己无法找到解决方案......

一些mysql大师可以帮助我吗?

谢谢 :)

4

1 回答 1

0
SELECT * FROM (
  SELECT datetime,
    CONCAT(users.id,'#_#',users.nickname,'#_#',users.avatar,'#_#',questions.datetime,'#_#',questions.question,'#_#',0000) as summary 
  FROM `questions` 
  join users on users.id = questions.id_user 
  WHERE questions.id = 12 
  union 
  select datetime,
    CONCAT(users.id,'#_#',users.nickname,'#_#',users.avatar,'#_#',answers.datetime,'#_#',answers.answer,'#_#',answers.id) as summary 
  from answers 
  join users on users.id = answers.id_user where id_question = 12
) A ORDER BY datetime

假设您的意思是 sort on datetime,而不是answers.datetime

于 2013-01-01T20:15:28.593 回答