vendredi 12 juillet 2019

Mysql where if condition

Basically I have a table all customer will have a default row with customer_group_id=0

But some of this customer will belong to customer_group_id=1

When that happen a new row is created for customer with customer_group_id=1 therefore now I have 2 rows for same customer but different customer_group_id.

Now when I fetch the data I need first to select * from customer table where customer_group_id =1 but if doesn't exist give me then with customer_group_id = 0 which is the default, and continue until it returns all data.

Anyone know the best way to achieve this fast?

Aucun commentaire:

Enregistrer un commentaire