sql - Condition in Mysql while selecting data form different tables -
i have code , working perfectly, have added 2 new columns in orders
table in database:
guest_user ('y'/'n'
)guest_phone
what want if guest_user
'y'
don't have users.email
replace orders.guest_phone
.
how this. can fix please....
select distinct orders.id 'order id', users.email 'email', orders.price 'amount', orders.city_sj 'city', orders.order_from 'web/app', orders.payment_status 'cod/pwc', orders. @ 'date , time' users, orders, order_history users.id = order_history.uid , orders.id = order_history.oid , orders. real = 1 , orders.price > 1 , orders. status = 1 order orders.id;
running above code getting below type of output:
thanks
something should job want:
select distinct orders.id 'order id', if(orders.guest_user = 'y', orders.guest_phone, users.email) 'phone/email', orders.price 'amount', orders.city_sj 'city', orders.order_from 'web/app', orders.payment_status 'cod/pwc', orders.at 'date , time' users join order_history on users.id = order_history.uid join orders on orders.id= order_history.oid orders.real=1 , orders.price>1 , orders.status=1 order orders.id;
you should use explicit join syntax instead of old style implicit style.
Comments
Post a Comment