title: How to get number of records along with min/max values in MySQL?
body: <p>I have a search form (running <code>MySQL 5.0.88</code>) to drill down through a product table. The search is a 2-step search. First run gets the <code>number of results</code>, 2nd run gets the <code>data of records x-y</code>.</p>
  
  <p>I'm displaying min/max prices across all records by default and now want to update the min/max values based on the query results. I was thinking the best way to do this is inside the inital query, that gets the number of records.</p>
  
  <p>Currently it looks like this: </p>
  
  <pre><code>SELECT  COUNT( a.id ) AS recordcount
          , a.nos
          , a.nos_anzeige
  
  FROM artikelstammdaten a
  
  WHERE 
          a.iln != "1111111111111" AND a.iln != "2222222222222" AND a.iln != "7777777777777"
      AND a.aktiv = "ja"
      AND a.artikelnummer LIKE '%name%' 
  AND (a.modus = "OPEN" 
          OR a.iln IN ( 55555555555,66666666666,2222222222222 ) 
          )
  
  GROUP BY a.iln, a.artikelnummer, a.preis_aktuell, a.artikelbezeichnung
  HAVING (( sum(a.bestand) != 0 ) OR (a.nos = "ja" AND a.anzeige  = "ja" ))
  </code></pre>
  
  <p>Which gives me all matching records. </p>
  
  <p><strong>Problem</strong>:<br>
  Actually I only want the number of records (~ <code>query.recordcount</code> ) in a single record and not the individual records one by one (my attempt with <code>COUNT</code> doesn't work). Something like this: </p>
  
  <pre><code>  totalrecords    min-price   max-price
    12345           9.99        1.204
  </code></pre>
  
  <p>where I can try to select min/max values across the resultset.</p>
  
  <p><strong>Question</strong>:<br>
  How do I have to modify my query, so I'm only getting the totalrecords (and can try to add min/max values)? </p>
  
  <p>THANKS!</p>
  
  <p>** EDIT: **<br>
  My table looks like this:</p>
  
  <pre><code> CREATE TABLE dummy (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `iln` VARCHAR(13) NULL DEFAULT NULL,
  `ean` VARCHAR(35) NULL DEFAULT NULL,
  `artikelnummer` VARCHAR(35) NULL DEFAULT NULL,
  `preis_ek` DECIMAL(12,2) NULL DEFAULT NULL,
  `preis_vk` DECIMAL(12,2) NULL DEFAULT NULL,
  `firma` VARCHAR(35) NULL DEFAULT NULL,
  `nos` VARCHAR(4) NULL DEFAULT NULL,
  `nos_anzeige` VARCHAR(4) NULL DEFAULT NULL,
  `aktiv` VARCHAR(4) NULL DEFAULT NULL,
  `modus` VARCHAR(4) NULL DEFAULT NULL,
  `bestand` DECIMAL(10,0) NULL DEFAULT '0'
   )  
  </code></pre>
  
  <p>Prices would be <code>preis_ek</code> and <code>preis_vk</code> where I'm looking for min/max for each. THANKS!</p>
  
  <p><strong>EDIT</strong>: 
  Running the query like it is gives me a resultset like this:</p>
  
  <pre><code>"id"    "nos"   "nos_anzeige"   "MIN(a.preis_ek)"
  "1153837"   "nein"  "nein"  "25,10"
  "1153797"   "nein"  "nein"  "12,40"
  ....
  </code></pre>
  
  <p>which picks the <code>min</code> per record not across the resultset, if I'm not mistaken</p>