mySQL - if...else condition help....

Discussion in 'MySQL' started by cancer10, Aug 18, 2008.

  1. cancer10

    cancer10 New Member

    Joined:
    Jul 12, 2008
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Webmaster
    Location:
    India
    Hi there,


    I have a table - mytable and the columns in the table are as follows:


    CityName (varchar)
    updated_by (varchar)
    added_by (varchar)

    The first column is a city column, someone would add/update the city names and accordingly their name would be updated/added to the updated_by and added_by columns. Now, the condition of my query would be:

    - if the updated_by column is NOT empty and the added_by column is empty, then the value of the updated_by would show .

    - if the added_by column is NOT empty and the updated_by column is empty, then the value of the added_by column would show.

    - if both added_by and updated_by columns are NOT empty then the value of the updated_by would show.



    Could this be done in one single query? If yes, how (example plz)?


    Thanx in advance
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Code:
    IF(added_by IS NULL AND updated_by IS NOT NULL,updated_by,added)
    
    I wrote a part, you can write whatever condition you want this way!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice