Nrc
Nrc

Reputation: 9787

Insert in an existing row

How can I INSERT INTO an empty field without creating a new row?

If I understand:

I cannot use insert into with a where clause:

INSERT INTO consulta (tema)  
value('prova')  
WHERE client=1;

I can update with a where but I cannot do that if the field is empty :

UPDATE consulta      
SET tema=prova  
WHERE client=1;

So how should I insert in an existing row?

Upvotes: 0

Views: 906

Answers (4)

dimma314
dimma314

Reputation: 21

I think the problem may be you are missing the quotes around the value you are trying to set.

Try:

UPDATE consulta       
SET tema='prova'  
WHERE client=1;

Upvotes: 1

Haji
Haji

Reputation: 2077

You need to use update statement if the row already exists You can check the values as empty in where class. use the below query

update consultaSET tema='prova' WHERE tema='' and client=1

Upvotes: 0

rralcala
rralcala

Reputation: 158

I think you're trying to update actually, insert into is allways intended for creation, unless you use replace into which will over write your row ONLY IF there if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, (From Mysql 5 reference But I don't know which DBMS you're using

From your update statement I see that prova doesn't have '', maybe that is your problem.

You should use: UPDATE consulta SET tema='prova' WHERE client=1;

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269443

Do you want one of these?

UPDATE consulta
SET tema=prova
WHERE client is null;

or

UPDATE consulta
SET tema=prova
WHERE client = '';

"Empty" doesn't have a technical meaning in SQL, so it could be either.

Upvotes: 1

Related Questions