sql - MySQL column sorting issue using derived tables with union -
looking little on query. i'm trying sort results using p.timer column in descending order. error every derived table must have own alias believe issue clubs table needs alias, not sure if that's problem?
thanks in advance pointing me in right direction on this.
select * ( select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 1 rank `names` p inner join `clubs` g on p.club_post = '1,3,4,5,6' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1' order p.timer desc limit 0,1) union ( select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 2 rank `names` p inner join `clubs` g on p.club_post = '2' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1' order p.timer desc limit 0,1) union ( select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 3 rank `names` p inner join `clubs` g on p.club_post = '10' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1,2' order p.timer desc limit 0,1) union (select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 4 rank `names` p inner join `clubs` g on p.club_post = '11' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1,2' order p.timer desc limit 0,1) union (select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 5 rank `names` p inner join `clubs` g on p.club_post = '7' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1' order p.timer desc limit 0,1) union (select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 6 rank `names` p inner join `clubs` g on p.club_post = '1,2,3,4,5,6' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '2' order p.timer desc limit 0,1) order rank,p.timer desc limit 0, 5
the union used wrong in query. here correct usage, though query ugly.
select * ( select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 1 rank `names` p inner join `clubs` g on p.club_post = '1,3,4,5,6' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1' order p.timer desc limit 0,1 union select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 2 rank `names` p inner join `clubs` g on p.club_post = '2' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1' order p.timer desc limit 0,1 union select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 3 rank `names` p inner join `clubs` g on p.club_post = '10' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1,2' order p.timer desc limit 0,1 union select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 4 rank `names` p inner join `clubs` g on p.club_post = '11' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1,2' order p.timer desc limit 0,1 union select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 5 rank `names` p inner join `clubs` g on p.club_post = '7' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '1' order p.timer desc limit 0,1 union select p.id,p.display_title,p.industry,p.location,p.timer,p.club_post,i.name,l.city,l.stateabbr, 6 rank `names` p inner join `clubs` g on p.club_post = '1,2,3,4,5,6' inner join places l on l.id = p.location inner join workforce on i.id = p.industry p.status = '1' , p.status_1 = '1' , p.category = '2' order p.timer desc limit 0,1 ) subtable order rank,p.timer desc limit 0, 5
Comments
Post a Comment