SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Adding 2 tables together

    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.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
      ( SELECT 5 as sortkey, * FROM news5 )
    union all
      ( SELECT 4 as sortkey, * FROM news4 )
    ORDER BY sortkey desc, ID 
    LIMIT 0,10
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •