select from 3 tables order by date

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

select from 3 tables order by date

Post by itsmani1 »

Hi


I have three tables birthdays, events, holidays I want to fetch data from all three tables order by date. Can i do this? if i can what's the way?

Regards,
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: select from 3 tables order by date

Post by VladSun »

By using UNION?
Also, use a constant column to distinguish records from the 3 tables, if you need to.
E.g.:
[sql]SELECT    1, .....FROM    table1unionSELECT    2, ....FROM    table2[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply