I have this table:
table session(
ID number,
SessionID VarChar,
Date,
Filter
)
This table contains searches info, like this:
ID SessionID Date filter
4 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=5
6 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon
7 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon&meagPixel=12.1
8 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon
10 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Nikon
12 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=12.1
13 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=12.1&opticalZoom=True
14 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 meagPixel=12.1&opticalZoom=True&brand=Panasonic
16 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=500.00
18 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=499.00
19 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=499.00&brand=Olympus
21 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000
22 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica
23 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica&price=1995.00
24 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True
25 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2
26 peqq421gaspts3nuulq5mwcq 24/05/2012 13:50 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2&weight=345
27 peqq421gaspts3nuulq5mwcq 24/05/2012 13:58 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2
41 poiq41111spts00000q5aaaa 27/05/2012 13:48 meagPixel=5
I want to get unique searches. Unique searches are:
- the longest search(filter) of the user(session)
- if the first filter has changes - it needed to be treated as new search(filter)
Since ASP.NET doesnt guarantee the SessionID is unique (SessionID,Date) is unique.
I didnt get far after:
SELECT MAX(Filter)
FROM Session
GROUP BY SessionID
BTW the result for the example table data I gave should return this:
ID SessionID Date filter
4 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=5
7 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon&meagPixel=12.1
10 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Nikon
14 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 meagPixel=12.1&opticalZoom=True&brand=Panasonic
16 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=500.00
19 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=499.00&brand=Olympus
26 peqq421gaspts3nuulq5mwcq 24/05/2012 13:50 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2&weight=345
41 poiq41111spts00000q5aaaa 27/05/2012 13:48 meagPixel=5
Thanks for any help and guiding.
@GarethD - Tx for Schema and insert query. I have tried slight different approach. I am not sure if this will work in all scenario. It worked in mysql and mssql.
This gives exact result as required in Question.