woolyg Posted August 8, 2007 Share Posted August 8, 2007 Hi all, Ive got 2 tables, both of which have exactly the same field names, but different data in the tables. I want to get name 3 fields in my mySQL query, and get data to display from both tables: Table 1: ------------------------------------------------- | House_Name | House_Desc | Date_Added | ------------------------------------------------- | MyHouse | Lovely | 27-08-2006 | | YourHouse | NotLovely | 17-06-2007 | ------------------------------------------------- Table 2: ------------------------------------------------- | House_Name | House_Desc | Date_Added | ------------------------------------------------- | OldHouse | Horrid | 07-08-2006 | | NewHouse | Warm | 02-06-2007 | ------------------------------------------------- I would like to set up a query with the result showing 3 fields, sorted by date: RESULT: ------------------------------------------------- | House_Name | House_Desc | Date_Added | ------------------------------------------------- | NewHouse | Warm | 02-06-2007 | | YourHouse | NotLovely | 17-06-2007 | | OldHouse | Horrid | 07-08-2006 | | MyHouse | Lovely | 27-08-2006 | Can anyone help? The result set I'm getting is basically the two tables side by side, depending on which join type I use. I'd like to combine the results into 3 neat fields... Cheers, Woolyg Quote Link to comment Share on other sites More sharing options...
pikemsu28 Posted August 8, 2007 Share Posted August 8, 2007 use the UNION syntax http://dev.mysql.com/doc/refman/5.0/en/union.html $query="(select * from Table1) UNION (select * from Table2) order by Date_Added Desc"; Quote Link to comment Share on other sites More sharing options...
woolyg Posted August 9, 2007 Author Share Posted August 9, 2007 Ah cool, thanks for the reply! Woolyg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.