0

I found this answer but I'm not sure it does what I want to. It looks like it updates ALL rows in the table, where I only want to update one.

My table is very simple:

MacAddress | Name 1C-6F-65-C6-20-0B | Logan-PC DE-AD-BE-EF-F0-0D | PC1 ... 

MacAddress is the PK and I want to simply be able to update Name if it exists or add a new row if it does not, given the MacAddress as references and a Name string.

This is the first time I'm using SQLite so I may just not be understanding Eric B's answer correctly.

1
  • INSERT OR REPLACE INTO MyTable ("MacAddress ", "Name") VALUES ("1C-6F-65-C6-20-0B", "PC2") Commented Apr 20, 2013 at 14:52

1 Answer 1

1

The answer you posted seems to work well for me assuming your MacAddress is a primary key in your table.

insert or replace into yourtable (macaddress, name) values ('1C-6F-65-C6-20-0B', 'Logan-PC'); insert or replace into yourtable (macaddress, name) values ('1C-6F-65-C6-20-0B', 'Logan-PC-Updated'); 

SQL Fiddle Demo

This will result in a single row, with Logan-PC-Updated as the updated name.

NOTE: If your MacAddress is not your primary key, then this method will not work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.