sql - how to fetch this data in one query? -
i want fetch data in simple query
i use
select user_id , order_id product order_id = 3 group user_id , order_id ;
but result 1 row group
example input:
#user_id #order_id 1 2 1 3 2 3 2 4 3 1 3 4 3 5 4 1 4 3 4 12 4 6 5 4
where order_id = 4 then
output :
#user_id #order_id 2 3 2 **4** 3 1 3 **4** 3 5 5 **4**
try this:
select p2.user_id, p2.order_id product p1 inner join product p2 on p1.userid = p2.userid p1.order_id = 4
this should effective way data. if slow you, should create proper indexes on product
table.
also note work specifying 1 single order_id
, need adjustments more order_id
s (distinct
, specific) , bigger difference selecting userid.
Comments
Post a Comment