List:General Discussion« Previous MessageNext Message »
From:Grant Giddens Date:December 30 2005 4:00pm
Subject:Can I go a boolean search and get the row count in 1 SQL query?
View as plain text  
Hi,
  
    I have a web app where I am doing a boolean search.  I only  want to return 10 results
per page, but I'd also like to know how many  total rows match the search query.  I'm
currently performing this  with 2 query statements:
  
  1. (To get the actual rows via the search)
  
  SELECT $product_column[title],
              MATCH (title) AGAINST ('$q' IN BOOLEAN MODE)
              AS score FROM $product_table
              WHERE MATCH (title) AGAINST ('$q' IN BOOLEAN MODE)
              ORDER BY score DESC
              LIMIT $lower_limit,10
  
  2.  (To get the total number of results)
  
  SELECT COUNT(*) as num_results
              MATCH (title) AGAINST ('$q' IN BOOLEAN MODE)
              AS score FROM $product_table
              WHERE MATCH (title) AGAINST ('$q' IN BOOLEAN MODE)
              ORDER BY score DESC
  
  The queries might be a bit off as I don't have the exact code in front of me right now.
  
  Is there a way I can combine this into 1 query?
  
  Thanks,
  Grant
  

		
---------------------------------
Yahoo! Photos
 Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.
Thread
Can I go a boolean search and get the row count in 1 SQL query?Grant Giddens30 Dec