Friday, 15 June 2012

php - If input name found in SQL then do else do… with an SQL query -


I am trying to write a SQL query that in column 'RNname' is a name in the table 'Individuals' Will check for "Jack" and if he exists, then update that row and enter a new row with the new RN.

I'm trying to make IF / ELSE statements, but how do they actually work or do I want to do without ALSE? (I did not do a lot of this SQL work, I used to update only, like INSERT, DELETE, ALTER ... stuff.

I still have this: (If found in Jack Go to the RNN line then update, otherwise select new line from INSERT)

  select from individuals if 'jack' == rName BEGIN [update statement] finally [INSERT statement] END  

Edit: I do not think I explained a lot which I wanted, R is not unique to everyone. There should be no, no one should be 2. I've tried on duplicate key updates, but this is just new line with a new data. But I update it with the existing RNName (jack) line with new data Want to be RNNAM (Jack) in the same way, but other fields in that row should be updated in the new data given.

In your case:

  (The `Arnam`,` Foo`) values ​​( 'Jack', 'bar') duplicate key Adytn` foo` = value ( `Bar`); It is a unique key to do this work if there is a 'jack' in the table, then it is field with the 'bar'  Foo  and if there is no 'jack', it inserts a new line with  rName  = 'jack' and  foo  = ' times'. 


No comments:

Post a Comment