sql - How to change my Query to a single command in MySql? -
my order has 2 fields called buyerid , sellerid. want both id according same condition, can use 2 search statements union them, have search them 2 times. how search them 1 time in 1 select statement? statement is:
select sellerid order status=2 , createtime>'2015-05-25 8:00:00' union select buyerid order status=2 , createtime>'2015-05-25 8:00:00'
how change them 1 statement?
-- try change equal above,but wrong. select (buyerid+sellerid) order status=2 , createtime>'2015-05-25 8:00:00'
this you're looking for, if understood right:
select q.id (select sellerid id, status, createtime order union select buyerid id, status, createtime order) q status=2 , createtime>'2015-05-25 8:00:00'
i'd still go first attempt, not sure wether solution more efficient.
Comments
Post a Comment