sqlite3 - SQL - Updating a column based on values from another query -


Still new to SQL My goal is to find the last stamp event and update the last session column per user. I created a query that is finding the last stamp for every user in the database. I want to update property_last_session_date based on property_user_id

I am currently running SQLite3 and all 3 columns defined as Varchar (255)

Here is my code that I am trying to run.

  Update Tb1 set tb1.property_last_session_date = tt1.property_timestamp tableEvents Join Tb1 (select tb2.property_user_id, from table (tables2tproperty_timestamp) to tb2.property_user_id by TB2 group) on TT1 Tb1.property_user_id = tt1.property_user_id  

Thanks for the help!

After

  update tb1 set tb1.property_last_session_date = (to (tb2.property_user_id, max (tb2. Property_timestamp) Select the property_timestamp as tt1.property_timestamp Select Table Aventus TB2 Group by TB 2.property_user_id) TT1 WHERE tb1.property_user_id = tt1.property_user_id);  

This is called a correlated subquery, you can select it in SELECT, UPDATE, DELETE.

Note that this subquery has been killed for each line of Tb1.

However, MySQL should be very clever to perform TT1 only once.

This query will update all the rows in TB1 There may be some problem with rows where tb1.property_user_id is empty (tb1.property_last_session_date will be set to zero)

  Update Tb1 set property_last_session_date = (select prop_time from (property_user_id user_id, select as max_timestamp) as prop_time tableEvents tb2 GROUP by property_user_id) tt1 WHERE tt1.user_id = property_user_id);  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -