XpertWorlock Posted July 21, 2011 Share Posted July 21, 2011 Hey guys, I have a SQL query that goes like this SELECT page FROM keywords WHERE keyword_id = '17' UNION SELECT page FROM keywords WHERE keyword_id = '36' ORDER BY weight DESC SQL TABLE goes as this keyword_id page weight 17 example.php 20 36 example.php 80 17 test.php 5 36 test.php 10 So for this example, I need the results to return the "example.php" row first. I need it to add the 2 weights together (100,15) by page So the outcome would be : example.php test.php Any help guys Link to comment https://forums.phpfreaks.com/topic/242566-i-need-the-sum-of-2-queries-than-ordered/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 21, 2011 Share Posted July 21, 2011 SELECT page FROM keywords WHERE keyword_id IN(17,36) GROUP BY page ORDER BY SUM(weight) DESC You would only use a UNION when you have more than one table. Link to comment https://forums.phpfreaks.com/topic/242566-i-need-the-sum-of-2-queries-than-ordered/#findComment-1245803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.