sql - MySQL - join two queries the second being filtered by the result from the first -
i have situation rearch return single product sku return example:
select pr.sku, pr.pksku, pr.colordescription, pr.commonbrandname, pr.basemodel tbl_products pr pr.pksku = 160386 order pr.commonbrandname, pr.sku, pr.standardcolor
but sku may have other alternative colours available linked via basemodel , need display these know can writing new query so:
select pr.sku, pr.pksku, pr.colordescription, pr.commonbrandname, pr.basemodel tbl_products pr pr.basemodel = "result previous query" order pr.commonbrandname, pr.sku, pr.standardcolor
but combine 1 query, possible ?
secondly if need results ordered sku's returned 1st query listed first so:
searched sku
alternative color
searched sku
alternative color alternative color
searched sku
alternative color
etc.
it this
select pr.sku, pr.pksku, pr.colordescription, pr.commonbrandname, pr.basemodel tbl_products pr inner join tbl_products pr1 on pr.basemodel = pr1.basemodel pr2.pksku = 160386 order case when pr.pksku = 160386 0 else 1 end, pr.commonbrandname, pr.sku, pr.standardcolor
Comments
Post a Comment