smith.james0 Posted May 21, 2013 Share Posted May 21, 2013 I have had a good look on google and a few evening trying to get it to work, but I am no further. I have two querys The first is to get the all the information for the page from db main SELECT * FROM main WHERE Category = '$sql_Category' ORDER BY `main`.`Name` ASC LIMIT $page, $limit and the second is to get the rating for the first SELECT `item`, (`totalrate` / `nrrates`) AS `rank` FROM `rtgitems` ORDER BY (`totalrate` / `nrrates`) DESC The item column in rtgitems uses the id from the main table as a reference between the two. I would like to sort the result in the first query by ranking score taken from the second table like SELECT * FROM main WHERE Category = '$sql_Category' ORDER `item`, (`totalrate` / `nrrates`) AS `rank` FROM `rtgitems` ORDER BY (`totalrate` / `nrrates`) DESC can this be done? James Link to comment https://forums.phpfreaks.com/topic/278248-combining-two-sql-querys/ Share on other sites More sharing options...
Psycho Posted May 21, 2013 Share Posted May 21, 2013 SELECT main.*, rtgitems.item, (rtgitems.totalrate / rtgitems.nrrates) AS rank FROM main JOIN rtgitems ON rtgitems.item = main.id WHERE main.Category = '$sql_Category' ORDER BY main.`Name` ASC, rtgitems.totalrate / rtgitems.nrrates) DESC LIMIT $page, $limit Link to comment https://forums.phpfreaks.com/topic/278248-combining-two-sql-querys/#findComment-1431426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.