27 Dec 2016

MySQL Query

Copy Data form one table to another table.

INSERT INTO `tbl_tbl1` [(fields )]
SELECT [clmns] FROM `tbl_tbl2`;
  ------------------------------------------------------------------------------------------------------------------

Get / Find Changed Values form table 1 to table 2

SELECT mfg_part_no FROM `tbl_comp_prod1` AS cp1
WHERE  CONCAT(cp1.mfg_part_no,cp1.price) NOT IN
(SELECT CONCAT(mfg_part_no,price) FROM tbl_comp_prod2)
OR CONCAT(cp1.mfg_part_no,cp1.`msrp`) NOT IN (SELECT CONCAT(mfg_part_no,msrp) FROM tbl_comp_prod2);

Yii DB Commend Tricks

To Truncate Table

Yii::$app->db->createCommand()->truncateTable('tbl_table1')->execute();

To Execute SP

 Yii::$app->db->createCommand("CALL vendor_file_upload();")->execute();

Bulk Insert in CSV File
$qry = "LOAD DATA INFILE '/path/store.csv'
INTO TABLE `tbl_table2`
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS ";
            Yii::$app->db->createCommand($qry)->execute();



public function getDeffData() {
        $data = Yii::$app->db->createCommand("CALL getDeffData();")->queryAll();
        return count($data) ? $this->getDeffDataObj($data) :[];
    }