Skip to main content

Inserting and updating multiple rows by using INSERT and SELECT subqueries

How to insert data from one table to another table efficiently?
How to insert data from one table using where condition to another table?

Let's have a look on it:-

SELECT subquery in the INSERT statement can be used to add values into a table from one or more other tables or views. Using a SELECT subquery also lets more than one row be inserted at the same time.

INSERT INTO `table1`
 (`id`, `user_id`, `name`, `is_default`,  `entity_status`)
SELECT NULL, table2.id, 'General', 1, 'Active'
FROM table2;


Above example will retrieve the all the id from table2 and insert it into table1 with the other data.


UPDATE `table1
JOIN table2 on table2.academic_session_id = table1.academic_session_id
SET table1.fee_structure_master_id= table2.id
WHERE table2.is_default = 1;

Above example will retrieve the all the id from table2 and update it into table1

Comments

Popular posts from this blog

Configure MySQL to handle camel case (or case sensitive) table names and column names

The default settings provided of MySQL enforce a strict lowercase conversion for all the table and database names. To allow camel case in mysql we need to made following changes in mysql configuration file.   lower_case_table_names It can easily be added to the MySQL my.ini file, usually found in the following folder: C:\xampp\mysql\bin The easiest way to take care of this is to add the following to your my.ini file under the [mysqld] section. [mysqld] ... lower_case_table_names = 2 And Restart Xampp.

Upload files to AWS S3 using laravel

Today, I am going to share with you How to file upload in AWS s3 using Laravel 5. Laravel 5 introduce new feature in FileSystem that makes easy to upload file or image or docs etc in S3 server. When we use s3 driver for Storage FileSystem we require to install "league/flysystem-aws-s3-v3" composer package for amazon api. So you have to just follow few step to do this from scratch. First we need to install flysystem-aws-s3-v3 Package. Run below command in CMD/Terminal composer require league/flysystem-aws-s3-v3 Now you have to add following details on your config/filesystems.php file. 's3' => [             'driver' => 's3',             'key' => 'aws-access-key',             'secret' => 'aws-secret-key',             'region' => 'aws-region',             'bucket' => 'bucket-name,      ...

Ionic Cordova FCM Execution failed for task ':app:processDebugGoogleServices' Error

I am new to Ionic framework version1 and working on an ionic app. I am trying to make push notifications work through FCM(Firebase Cloud Messaging ), with cordova-plugin-fcm-with-dependecy-updated  plugin in ionic. When I run ionic cordova build android , it gives build failure error: Execution failed for task ':app:processDebugGoogleServices'. > No matching client found for package name 'io.ionic.starter'  I am sharing it because if anyone has the same problem, Please check the widget id in config.xml and package_name in google-services.json are the same.