July 30, 2010 at 12:43 pm
If you have a web site and database that allows people to search.. What is the general strategy if you would like to record how many times a record appears in search results? I could-execute the search (SELECT) query as an UPDATE query to update a "counter" field, but then I'd always be executing two queries every time a search is performed. Seems like a headache.
July 30, 2010 at 2:08 pm
Could not see SQL Server element in the question
Pradeep Adiga
Blog: sqldbadiaries.com
Twitter: @pradeepadiga
July 30, 2010 at 4:42 pm
It is SQL 2008.
July 30, 2010 at 11:09 pm
U can use another table to store searched record... Before insert.... check whether it is there in the new table... if exists... update its counter... else insert it...
or else u can use group by....
August 1, 2010 at 9:59 pm
tx for the info, but i didn't understand what you are saying..
August 2, 2010 at 1:29 am
Try aggregating the result set
Select field1, field2, count(field)
from
table
where some condition = whatever
group by field1, field2
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply