1

I want to return a limted result for a query, but at the same time return all DISTINCT values as if no limit was set.

SELECT artnr, color FROM table WHERE catID=1 LIMIT 20
SELECT DISTINCT(color) FROM table WHERE catID=1

If a user selects all products with catID=1, this will return a limited result. I want to show the user all possible colors for this category, so the user can select a specific color.

Can this be done in one query, or does it require seperate querys as above?


Let say I grab all rows without a limit. Then with php I could use an array to grab distinct color values.

SELECT artnr, color FROM table WHERE catID=1

$color_array = array();  
while($row... {  
 $color_array[$row["color"]];  
}  
for($a=0;$a<20;$a++) {  
  // Print 20 rows from the result  
}  

But I want to LIMIT the result, and still grab ALL color value.

4
  • 4
    I don't get it. Could you post some of your example data as well as the expected result? Oct 18, 2012 at 15:57
  • You really should do it with two separate queries.
    – lanzz
    Oct 18, 2012 at 16:09
  • are you running above query from DB level or from some application?
    – PyQL
    Oct 18, 2012 at 16:11
  • @Bader - running from db. What is comes down to is beeing able to grab filter information regarding content. I dont want to show all possible values for ie. color, only those that exists in the current selection. But maby I need two seperate queries as $lanzz say
    – Fralla
    Oct 18, 2012 at 16:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.