How to apply the conditions if/else in SQL?



  • There's a sample in the variable.

    Specify how to apply the conditions if/else Total sql♪ For example, if advert.hide='show' ... otherwise.

    $db_query="select *
        from ".DB_PREF."advert advert"
        ." where "
        ." advert.hide='show'  "
        ." and advert.end_putdate > ".$GLOBALS["timeGlobal"]." "
        ." order by premium_adv DESC, sort_time DESC limit ".KOL_NEW_ADVERT_TO_GLAV;
    


  • Use your function. IF:

     select IF (advert.hide='show', 'Опубликовано', 'Скрыто') from ...
    

    The function looks general, so:

    IF(expr1,expr2,expr3)
    

    If expr1 The truth then. IF() returns expr2Otherwise returning expr3


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2