hI
I have 2 tables name master and client
my master table looks like:
my client table looks like:
I want to compare item_count of master table and item value in client table to make changes in client table
First change that I want to do is :
When item_count =1 in master table and item >1 in client table , then I wish to replace all these entries in client table having item>1 to item =1
(so for eg: here i will replace 2 entries in client table who have item>1)
So I used this to find the entries:
But how should I update them?
Is this wrong?
I have 2 tables name master and client
my master table looks like:
Code:
+-----------+--------+--------+--------+--------+-----------------+---------------+-----------+------------------+
| name | mall_id | type | start | end | 1_start | 1_end | item_count | Task_id |
+-----------+--------+--------+--------+--------+-----------------+---------------+-----------+------------------
| Straight6 | 7 | A | 561 | 728 | NULL | NULL | 1 | 1 |
| Straight6 | 7 | A | 19 | 97 | NULL | NULL | 1 | 1 |
| Straight8 | 7 | B | 58 | 100 | NULL | NULL | 2| 1 |
| Straight9 | 7 | B | 51 | 110 | NULL | NULL | 3| 1 |
+-----------+--------+--------+--------+--------+-----------------+---------------+-----------+----------------+
Code:
+-----------+-------+---------+-----+-------+-------+--------+--------+
| name | item | id |train | start | end | pick_id | type |
+-----------+-------+---------+-----+-------+-------+--------+--------+
| Straight6 | 1 | 1 | 4 | 561 | 080 | 7 | A |
| Straight6 | 2 | 1 | 5 | 561 | 610 | 7 | A |
| Straight6 | 3 | 2 | 4 | 311 | 431 | 7 | A |
| Straight8 | 1 | 1 | 5 | 561 | 610 | 7 | A |
| Straight8 | 3 | 2 | 4 | 311 | 431 | 7 | A |
| Straight9 | 6 | 2 | 4 | 311 | 431 | 7 | A |
| Straight9 | 3| 2 | 4 | 311 | 431 | 7 | A |
+-----------+-------+---------+-----+-------+-------+--------+--------+
First change that I want to do is :
When item_count =1 in master table and item >1 in client table , then I wish to replace all these entries in client table having item>1 to item =1
(so for eg: here i will replace 2 entries in client table who have item>1)
So I used this to find the entries:
Code:
select distinct m.name, item_count, item from master m join client p on m.name=p.name where item_count = 1 and item > 1;
Code:
Update from client Set item =1 where m.name=p.name and item_count=1 AND item>1