sql - combining 2 tables in mysql -


here looking have doubts if possible or not!

i have 2 tables, 1 called users , other answers. need combine results single statement, , order table time. tricky part have time on both tables , need take both time fields account ordering results.

this unsuccessful attempt come query:

select * ( select id, username, first_name, last_name, time users union   select id, answer, pid, uid, time answers ) ab order `ab.time` 

update

i have come following sql query:

 select username user, '' page , '' content , time users  union   select (select username users `id`=`uid`) user, pid page, answer content, time answers  order `time` desc 

its looking reason user field in second select query showing null! idea why?

 select id, username, first_name, last_name, time users union   select id, answer, pid, uid, time answers  order 'time` 

solution have different column name each table

select id         t1_id,         username   t1_username,         first_name t1_first_name,         last_name  t1_last_name,         null       ast2_id,         null       t2_answer,         null       t2_pid,         null       t2_uid,         time    users  union  select null   t1_id,         null   t1_username,         null   t1_first_name,         null   t1_last_name,         id     ast2_id,         answer t2_answer,         pid    t2_pid,         uid    t2_uid,         time    answers  order  time  

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - EclipseLink JPA Object is not a known entity type -

java - Need to add SOAP security token -