So the question is this. I have a table with n columns of data, but I want to list one row for each unique set of 3 columns.
For example, say the table is structured as below
ID | data1 | data2 | data3 | description | price | handler | creationTime | etc...
What I’m trying to do, is to use this subquery:
SELECT distinct data1, data2, data3 FROM Table_1
… to get each unique variation for the 3 columns. But then I want to select ONE full row from the table for each such result.
This query is meant for rather heavy use and needs to be optimized, which is kind of why I can’t use table variables or while loops. Any hints?
if you are using SQL Server, you can do this with a common table expression: