Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Sorting two tables that have been joined


Message #1 by "Carl E. Olsen" <carl-olsen@m...> on Sun, 26 Jan 2003 13:44:18 -0600
I've got two tables with identical fields, news and updates.  I want to
return an ASP record set with all the data from both tables, and then I
want to order it by the date.  Of course, there's a possibility of
duplicate dates.  I would prefer the record from the news table when
there are duplicate dates.

Right now, I'm using:

"SELECT * FROM News, Updates"

as my SQL string.  Currently, the last date is in the Updates table, so
moving to the last record in the record set produces the desired result.
However, if a story is added to the news table, I doubt it's going to be
the last record in the record set.

Is there any way to sort the record set on the date field after the two
tables are joined?

Carl Olsen, MCSE
Des Moines, IA


Message #2 by scott.murdock@o... on Mon, 27 Jan 2003 18:10:40
If I'm understanding you right, what you need to do is use an outer join 
with an ORDER BY clause.  It should look like...

"SELECT * FROM News UNION SELECT * FROM Updates ORDER BY [whatever your 
date field is called]"

Hope that solves your problem.

Scott Murdock
Intranet Applications Manager
Omnicom Group



  Return to Index