jeudi 21 avril 2016

How Can i Perform This Mysql Query With IF Condition

i have an existing Mysql Table with Data Loaded(TblParts)

Code Stock Price Location id
1     10   1000   Global  1
2     5    1500   Office  2
3     2    500    Global  3
4     1    100    Global  4

i Have a Second Table with New information(TblNewParts)

Code Stock Price Location id
1    30    2000    Global 1
2    5     1000    Global 2
3    10    5000    Global 3
4    30    200     Global 4
5    40    500     Global 5

i need to update TblParts with TblPartsNew data

if Code Exist, And Location = Global then Update Stock and Price if Code Exist, But Location <> Global then Insert Record with Same Code and Distinct Location if code Not Exist then Add it

The Output of TblParts Must Be:

Code Stock Price Location
1    30    2000   Global 
2    5     1500   Office 
3    10    5000   Global 
4    30    200    Global 
5    40    500    Global

Really i Dont Have Idea How To Perform This. Thanks In Advance

Aucun commentaire:

Enregistrer un commentaire