开发者

Problem while updating table in android

I created a table in the database that has the data like this:

Problem while updating table in android

Now i have written a query that updates the contact field by concatinating name and email fields: UPDATE MyContacts SET con开发者_开发百科tact=(SELECT name||'--'||email FROM MyContacts);

Here the problem is after executing the query the table is as below:

Problem while updating table in android

Why is it happening like this? In oracle i never faced this problem. Please help me. Thank you


Right now you're not specifying the correct row to retrieve the values from. Try something like this:

UPDATE MyContacts SET contact = name||'--'||email;

EDIT: Glad it worked. Your first issue was that your sub-select uses a SELECT statement with no WHERE clause (SELECT name||'--'||email FROM MyContacts will return 3 rows). One possible solution would be for SQLite to throw an error and say You've tried to set a column to the result of an expression that returns more than 1 row: I've seen this with MySQL and SQL Server. However, in this case SQLite appears to just use only the very first value returned. However, your second error then kicks in: since you don't narrow your UPDATE statement with a WHERE clause, it uses that first value returned to update EVERY single row, which is what you see.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜