SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2009
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Possible to make a default equal different entry in same table?

    just wondering if this is possible
    say I have news_title and news_date, can I make news_title default to news_date if not entered?

    this example I guess is a little more complicated because datetime has different display methods. But I'm curious to know either way.

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You'd have to use a trigger if you wished to make the db do this, or you could quite simply use which ever programming language you are using to check the data entered before it was sent off to the db and alter it before creating your query.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When selecting your data, provided that the news_title field is set to null if not specified, you can use the COALESCE function, which returns the first of its parameters which is not null.

    Code:
    SELECT COALESCE(news_title, news_date) AS title...
    Sam Hastings


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
  •