I am new to MySQL and I just cannot seem to get the answer I am looking for. Basically I have a table that contains events so the table is comprised of an autoincrement id and name field. I need to add records to the table as events occur and log the details of the events in a different table using the event id. If the event name exists in the table I need a stored proc/function to return the id field. If the name does not exist, the stored proc/function should insert the new event name and return the new event id.
Every search I have done leads to "Insert on Duplicate Key Update" but that does not fit the bill as I have to look up the key or create a new one. Hopefully I explained my issue well enough. Thanks in advance for any input.
If you choose to battle wits with the witless be prepared to lose.
Code:
pseudo code
Select ID From Events Where Name = sNewName
If Exists ID Then
Return ID
Else
Insert Into Events (Name) Values (sNewName)
Return newID
End If
If you choose to battle wits with the witless be prepared to lose.