怎么实现sql 从左边的表查出 成为 右边的数据
select * from ((select id, question as content from table1) union (select id, answer as content from table2) ) orderby id
建两个表,两个表通过id相关,通过左表的id即可查到右表相同id的内容。
SELECT question , content FROM emp e1 LEFT JOIN emp e2 ON e1.id = e2.id;
不是可以通过ID建立关联的嘛?
select l.*, r.* from left_table as l right join right_table as r on l.id = r.id
id关联的话,直接 join不就ok了吗?
ID不关联,直接join就可以吗
两个ID要关联,JOIN 就可以了。
或者,用左边的ID当作右边的查询条件,也可以的。就是麻烦了点。
select id ,question as content from table union select id ,anwser as content from table ;