Results 1 to 2 of 2

Thread: Sorting 4 Different Tables By Date

  1. #1
    Join Date
    Sep 2007

    Question Sorting 4 Different Tables By Date

    I'm working with a site where there are 4+ different types of items that can be on the front page (like photos, blog posts, reviews, etc) and these are stored in 4 different database tables that really can't be combined into one table easily.

    I want to sort these on the front page by date desc so the latest 5 are displayed. Currently i'm using a multiple dimension array to do this but I figure there's got to be a much easier way possibly through a MySQL view or join or something. All 4 columns have a DATE field to sort by...any ideas? All I would need to return is the type and the primary key and I'd be fine.

    Any help would be appreciated.

  2. #2
    Join Date
    Aug 2005
    The Garden State
    is it too late to make a 5th table, named "postings" that has structure something like

    posting_id int primary key
    posting_date datetime
    posted_item_id int (fake foreign key to one of those 4 tables)
    posted_item_table varchar(64) (the name of the table that id is in)

    if not, then surely all 4 of these tables have a posting date. you could just use union to bring them together, and then sort the union.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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