PDA

View Full Version : adding 2 db tables


ephemie
02-11-2005, 01:12 AM
I have 2 news tables (news4 & news5) with the same structure. (ID, Entry_Date, Title & Message)

At the moment I can display one table with:
strSQL = "SELECT * FROM news4 ORDER BY ID LIMIT 0,10"
Set rstCurrent = conCurrent.Execute(strSQL)

However, i would like to include the most recent records from news5 first. ie. Display table news5 and then news4.

If i include news5 as such "FROM news4, news5 ORDER
i get order problems.

Any help would be appreciated. With thx.

Brandoe85
02-11-2005, 05:59 PM
Maybe you want to look into joins (http://www.w3schools.com/sql/sql_join.asp)

waolly
02-11-2005, 06:32 PM
Suppose you had some rows in each table all with varying dates.

Do you want to select all rows from news5 in date order and then have all rows from news4 in date order but listed after news5's rows?

If so the code below may help. You use the union to combine the two tables and then specify an extra field which is a number (I named it "s") and sort on that extra field and then the entry date.


select *,1 s from news5
union
select *,2 s from news4
order by s asc,entry_date desc