If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > If else stetement?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-04, 11:38
xayavon xayavon is offline
Registered User
 
Join Date: Dec 2003
Posts: 23
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.
Reply With Quote
  #2 (permalink)  
Old 02-02-04, 12:31
aus aus is offline
Registered User
 
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?
Reply With Quote
  #3 (permalink)  
Old 02-02-04, 12:56
xayavon xayavon is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 02-03-04, 01:10
aus aus is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On