lundi 20 mai 2019

How to update a table from a select query

i am creating a temp table using DB facade and then using select query i need to update some columns in temp table based on condition

   DB::update('update table_temp_topcustomer 
               set ordercount = aaa.ordercount 
               from 
                (select count(id) as ordercount,mobileno 
                 from order_hdrs 
                 group by mobileno 
                ) as aaa
              where table_temp_topcustomer .mobileno = aaa.mobileno
              ');

it gives this error Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from (select count(id) as ordercount,mobileno from order_hdrs group by mobileno ' at line 1 (SQL: update table_temp_topcustomer set ordercount = aaa.ordercount from (select count(id) as ordercount,mobileno from order_hdrs group by mobileno ) as aaa )

How can i achieve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire