Frage

I just wondering, i have this query and i want to using Insert Into with where clause query syntax in sqlite, here's my query :

 INSERT INTO hubungan_univ (SELECT id_sma FROM hubungan_univ WHERE nama_univ = 'test')  VALUES (id); 

  also i've tried this

  INSERT OR IGNORE INTO hubungan_univ (SELECT id_sma FROM hubungan_univ WHERE nama_univ = 'test')  VALUES (id); 

here is my table :

 hubungan_univ

 id |  nama_univ | id_sma
 1  |  test      | (blank)

Then i want to fill id_sma where then name is test, but it's seem error, it's says near SELECT : syntax error, can anybody help me, I have search this code, but i can find the solution, Thanks

War es hilfreich?

Lösung

Looking at the SQL statement, I think you have the column definition and value around the wrong way.

Should it have been?

INSERT INTO hubungan_univ (id)
SELECT id_sma FROM hubungan_univ WHERE nama_univ = 'test';

Can you confirm whether or not you want to insert a new record with the id set to id_sma value of a record where the nama_univ value is 'test'?

I'm not completely sure I understand what you are trying to achieve.

If you want to fill the id_sma with the id value where the nama_univ is test, you should be using an update statement instead.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top