In sqlite I want to make a query that gets two values and use them to update two other…
Jump to turn (7)
- 1In sqlite I want to make a query that gets two values and use them to update two
- 2CAN YOU MAKE IT AS THERE IS ONLY ONE SELECT INSTEAD OF TWO FOR EACH VALUE?
- 3NO, YOU ARE STILL DOING TWO SELECTS, DO THE SAME WITH ONLY ONE SELECT
- 4if I add to this query the sentences "ORDER BY id DESC" and "limit 1", does that
- 5Ok i got it but I need to refactor this into a single method taking into account
- 6Ok but fSInt = subquery.fsi is only in CO tables but not in CT, does that would
- 7instead of if else use a ternary
- User
In sqlite I want to make a query that gets two values and use them to update two other values of a table with the same layout of the first but different name:
SELECT X AS X1,Y AS Y1 FROM Table1 WHERE (SOME-CONDITION)
UPDATE X=X1, Y=Y1 FROM TABLE 1
- Assistant
In SQLite, you can achieve this using a combination of a subquery and the UPDATE statement. Here's the query you can use:
codeUPDATE Table2 SET X = (SELECT X AS X1 FROM Table1 WHERE (SOME-CONDITION)), Y = (SELECT Y AS Y1 FROM Table1 WHERE (SOME-CONDITION)) WHERE (SOME-OTHER-CONDITION)This query will update the values of X and Y in Table2 with the values from X1 and Y1 in Table1, respectively, satisfying the given conditions.
Make sure to replace
(SOME-CONDITION)and(SOME-OTHER-CONDITION)with your actual conditions that define which rows to update.