database - MySQL - UNION and ORDER/SORT ROWS -
i retrieving table result/s using mysql's union feature. table containing ordered items sales order
below query used:
set @meta_id=0; select bsb.id meta_id, bsb.order_id order_item_id, '_product_id' meta_key, bsb.product_id meta_value, 1 origin b_sale_basket bsb bsb.order_id = 255 union select bsb.id meta_id, bsb.order_id order_item_id, '_qty' meta_key, bsb.quantity meta_value, 2 origin b_sale_basket bsb bsb.order_id = 255 ) sales_order_meta
the first query above retrieves ordered products having order_item_id of 255
while
second query above retrieves quantity of each product ordered
side note: in case ask why query them way since belong in same table, because i'm trying retrieve woocommerce ordered items...
the output of query above looks this:
http://i.stack.imgur.com/qpsjv.png
but, wish order results below each product ordered there quantity of each product ordered below them..
the final result want, looks this: http://i.stack.imgur.com/wx6aw.png
kindly please me...
you can use user-defined variable give rank each individual query first row query 1 have rank of 1 , first row of second query have rank of 1 , 2 ,3 on , order result row number
select bsb.id meta_id, bsb.order_id order_item_id, '_product_id' meta_key, bsb.product_id meta_value, 1 origin ,@r:= @r +1 `row` b_sale_basket bsb,(select @r:=0) t bsb.order_id = 255 union select bsb.id meta_id, bsb.order_id order_item_id, '_qty' meta_key, bsb.quantity meta_value, 2 origin ,@r:= @r +1 `row` b_sale_basket bsb,(select @r:=0) t bsb.order_id = 255 order `row`
edit
you can try order order_item_id,meta_key
Comments
Post a Comment