I’ve got a large query that pulls back contacts based upon a search. Here’s a simplified example of the query. (Table and field names have been changed to protect the innocent.)
SELECT DISTINCT TOP 20 DB1.FieldID, DB1.Field1, DB.Field2, DB.Field3,
DB2.Field88, DB3.Field77
FROM tblLamp DB1
LEFT JOIN tblSand DB2 ON DB2.FieldID = DB1.FieldID
LEFT JOIN tblLime DB3 ON DB3.FieldID = DB1.FieldID
WHERE (Field1 LIKE 'hotwet%' ESCAPE '!' OR Field2 LIKE 'maarten%' ESCAPE '!')
AND DB2.Field99 != '1111-2222-3333-4444'
AND (DB1.CreatorID IN (...) OR DB1.OwnerID IN (...) OR DB1.FieldID IN (...))
ORDER BY DB1.Field1 ASC, DB1.Field2 ASC
I’ve found a lot of examples on the web that use ROW_NUMBER() but I haven’t been able to get it working with this query. Any ideas?
You could use this small example as a guide: