jeudi 26 octobre 2017

select , delete and replace duplicate value

I have table Customer

+------------------------------------+
| id |   companyname   |    phone    |
+------------------------------------+
| 1  |      JACK       |    0111     |
| 2  |      JACK       |    0111     |
| 3  |      JONH       |    0222     |
| 4  |      WIM        |    0123     |
| 5  |      WIM        |    0123     |

and table Order

+--------------------------------+
| id | id_cus |    title job     |
+--------------------------------+
| 1  |    1   |     php          |
| 2  |    1   |     mysql        |
| 3  |    1   |     html         |
| 4  |    4   |     css          |
| 5  |    5   |     css3         |
| 6  |    2   |     jquery       |
| 7  |    3   |     react        |

Table Customer has foreign key to table Order. In table Customer I have value Phone is duplicate so I want delete value duplicate just keep last value. And replace last value into table Order my result look like this :

table Customer

+------------------------------------+
| id |   companyname   |    phone    |
+------------------------------------+
| 2  |      JACK       |    0111     |
| 3  |      JONH       |    0222     |
| 5  |      WIM        |    0123     |

and table Order

+--------------------------------+
| id | id_cus |    title job     |
+--------------------------------+
| 1  |    2   |     php          |
| 2  |    2   |     mysql        |
| 3  |    2   |     html         |
| 4  |    5   |     css          |
| 5  |    5   |     css3         |
| 6  |    2   |     jquery       |
| 7  |    3   |     react        |

How can I do this with Mysql or Query Builder Laravel, or Query Builder Yii2 ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lkbAKp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire