php - sql order and order_items tables but show shipping charge only once -
i have 2 tables orders , order_items
orders table
+----+-----------------------+ | id | total_shipping_charge | +----+-----------------------+ | 1 | 60 | | 2 | 60 | | 3 | 60 | | 4 | 60 | | 5 | 60 | | 6 | 0 | | 7 | 60 | | 8 | 0 | | 9 | 60 | | 10 | 60 | +----+-----------------------+
order_items table
+----+--------------------------+-----+-------+- | id | order_id | p_name | qty | price | +----+----------+---------------+-----+-------+--------------------------------- | 1 | 1 | product 1 | 1 | 699 | | 2 | 2 | product 2 | 1 | 349 | | 3 | 3 | product 3 | 1 | 199 | | 4 | 4 | product x | 2 | 299 | | 5 | 4 | product y | 2 | 299 | | 6 | 4 | product z | 2 | 299 | | 7 | 5 | product 7 | 2 | 299 | | 8 | 6 | product 8 | 1 | 1299 | | 9 | 7 | product 9 | 1 | 199 | | 10 | 8 | product 10 | 6 | 349 | +----+----------+---------------------------------------------------------------
now order_id 4 has multiple products in single order , when join 2 tables duplicate shipping cost. want shipping cost on first raw only.
i ran query
select o1.id, o1.total_shipping_charge, o2.order_id, o2.p_name orders o1 inner join order_items o2 on o1.id = o2.order_id
but shows duplicate row shipping cost, should show first row only.
| id | total_shipping_charge | order_id | p_name +----+-----------------------+----------+---------+ | 1 | 60 | 1 | product 1 | 2 | 60 | 2 | product 2 | 3 | 60 | 3 | product 3 | 4 | 60 | 4 | product x | 5 | 60 | 4 | product y | 6 | 60 | 4 | product z | 7 | 0 | 6 | product 7 | 8 | 60 | 7 | product 8 | 9 | 0 | 8 | product 9
from sql server perspective, asking not possible. asking report point of view different. can pull data , on report show way want can't pull data way.
not sure how mysql behaves.
Comments
Post a Comment