I’m using SQL Azure with asp script, and for the life of me, have had no luck trying to get this to work. The table I’m running a query on has many columns, but I want to query for distinct values on 2 columns (name and email), from there I want it to return the entire row’s values.
What my query looks like now:
SELECT DISTINCT quote_contact, quote_con_email
FROM quote_headers
WHERE quote_contact LIKE '"&query&"%'
But I need it to return the whole row so I can retrieve other data points. Had I been smart a year ago, I would have created a separate table just for the contacts, but that’s a year ago.
And before I implemented LiveSearch features.
One approach would be to use a CTE (Common Table Expression). With this CTE, you can partition your data by some criteria – i.e. your
quote_contactandquote_con_email– and have SQL Server number all your rows starting at 1 for each of those partitions, ordered by some other criteria – i.e. probablySomeDateTimeStamp.So try something like this:
Here, I am selecting only the last entry for each “partition” (i.e. for each pair of name/email) – ordered in a descending fashion by the time stamp.
Does that approach what you’re looking for??