Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Buzz50
Starting Member
1 Post |
Posted - 2012-01-11 : 10:49:22
|
| Hi,I am using the query below to retrieve rows where I get just the most recent row for each email field.It is very slow!Any ideas?The qid is a unique identifier.Thanks in advance!SELECT qid, postcode_area, vehicle_group, premium, lic_years, ncb, proposer_age, email, createdFROM Mainstreet.dbo.leads lWHERE created >= '01 January 2012 00:00:00.000'AND created <= '06 January 2012 23:00:00.000'AND scheme_id = 'PCH3'AND proposer_age >= 21AND proposer_age <= 29AND lic_years >= 1AND lic_years <= 5AND ncb >= 1AND ncb <= 5AND id = (SELECT MAX(id) AS Expr1FROM Mainstreet.dbo.leads leWHERE(le.email = l.email)) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-11 : 11:13:41
|
| instead of subquery try using a join on MAX(id) value and check------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|