0

I created a table in the database that has the data like this:enter image description here

Now i have written a query that updates the contact field by concatinating name and email fields: UPDATE MyContacts SET contact=(SELECT name||'--'||email FROM MyContacts);

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

enter image description here

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

0

1 Answer 1

2

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.

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

1 Comment

Thank you. It worked. But what is wrong with the statement i used. Can you please explain me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.