开发者

Selecting data from two tables

Hello everybody Well my question is about sql commands...

If I have 2 tables with the same number of columns and the same fieldnames (e.g: A(n,name,date) and B(n,name,date))

In the website, I want to retrieve data from both tab开发者_C百科les and display them in order by date descendent.

(The use of two tables is due to difference in tables database or server,or just the use of every table.. sometimes there's a need to display both tables in one order)

exemple

table Sport_news(N_event,Title,Texte,Date) table International_news(N_event,Title,Texte,Date)

Display:

  Christiano Ronaldo ... 2011/25/01
        christiano ronaldo is one of the famous...


  Barack Obama president of the USA...  2011/24/01
          Barak obama........

  The arsenal has... 2011/23/01
         Chamakh, player of arsenal is anger.....

I hope that the idea is clear : and thank you!


You want UNION

select a.name,a.date
  from table1 a
 where ...
 UNION ALL
select b.name,b.date
  from table2 b
 where ...
order by 2 desc

When you use a UNION, you specify the order by with column numbers instead of names.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜