tags:

views:

44

answers:

2

Suppose i have two tables... I want to get two tables data order by date posted/added or order by id!

so that if i have

table1
id msg              date
2  this is msg      nowdate

table2
id comment          date
2  this is comment  nowdate

Then how can i get it in single query order by id?

+4  A: 

UNION is the word, you are looking for:

(SELECT * FROM table1) UNION (SELECT * FROM table2) ORDER BY id
Residuum
A: 
 select t1.*, (t1.id) as id1, (t2.id) as id2, (t1.date) as date1, (t2.date) as date2, t2.* from table1 t1 inner join table2 t2 on t1.id = t2.id order by t1.id

 $arr = mysql_fetch_asssoc(above_query);
 echo $arr['id1'] // id of first table
 echo $arr['id2'] // id of second table
 echo $arr['msg'] // msg of first table
 echo $arr['comment'] // comment of second table
 echo $arr['date1'] // date of first table
 echo $arr['date2'] // date of second table
Sarfraz
but how can i display data from both tables in single mysql_fetch_array while i have two different fields i.e msg and comment
testkhan
i have updated my answer, see it again plz
Sarfraz