Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    23

    Unanswered: If else stetement?

    IF "1" != "0" THEN
    SELECT * FROM table1
    else
    SELECT * FROM table2
    END IF;

    I new to mysql syntax, so I don't see what the problem with this statement could be. Thanks for any suggestions.

  2. #2
    Join Date
    Oct 2003
    Location
    Denver, Colorado
    Posts
    137

    Re: If else stetement?

    Control structures for SQL syntax were not introduced into MySQL until version 5. Is there something wrong with the previous solution I gave you?

  3. #3
    Join Date
    Dec 2003
    Posts
    23
    Aus,

    I didn't know that my versin of mysql 4.0 didn't support control structure. And all this time I though it was just an syntax error. Are you referring to the REPLACE solution that you gave me. It works find, but I also need to "Select * from table1 where pk_ID = LAST_INSERT_ID();" if it is a new record. If it is an existing record I would like to "Select * from table1 where pk_ID = (the id that was updated). If there is an solution for this please let me know.

    Thanks,

    aus

  4. #4
    Join Date
    Oct 2003
    Location
    Denver, Colorado
    Posts
    137
    Well, you need a primary key or unique index inorder to have any effect using the REPLACE syntax. Use the unique value (or set of values) from your replace command. i.e. If you have
    Code:
    REPLACE INTO table1 SET uk1=firstval, uk2=secondval, data1=notnecessarilyuniquestuff;
    where uk* specifies a field in a unique index.
    Rather than looking for the row's primary key id and using WHERE pk=@pkid, use WHERE uk1=firstval AND uk2=secondval.

Posting Permissions

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