RE: I need help with SELECT statement



I think this will work:

SELECT DISTINCT a.col1, a.col2
FROM table1 a WHERE a.col3 =
(SELECT MAX(col3) FROM table1 WHERE col1 = a.col1 AND col3 <= @V)

"Vanessa Lee" wrote:

> Hi, Could you help me modify the SELECT statement below that would
> accomplish my final goal.
>
> SELECT col1, col2 FROM table1 WHERE col3 < @V
>
> In col1 rows have many duplicates
> col2 has unique values
> col3 can have 5 possible values: 5, 10, 15, 20, 25
> Variable @V can be equal to 5 or 10 or 15 or 20 or 25
>
> The goal is to:
>
> Return row values from col1 without duplicates, and return corresponding
> values from col2 (both col1 and col2 in one row) "WHERE" col3 always has
> maximum value from all possible values but is <= @V
>
> Thank you.
> Vanessa
>
>
>
.



Relevant Pages

  • Re: I need help with SELECT statement
    ... Could you help me modify the SELECT statement below that would ... > accomplish my final goal. ... > In col1 rows have many duplicates ... > Return row values from col1 without duplicates, ...
    (microsoft.public.sqlserver.connect)
  • Re: I need help with SELECT statement
    ... SQL Server MVP ... "Vanessa Lee" wrote in message ... > In col1 rows have many duplicates ... > Return row values from col1 without duplicates, ...
    (microsoft.public.sqlserver.security)
  • I need help with SELECT statement
    ... accomplish my final goal. ... In col1 rows have many duplicates ... col2 has unique values ... Return row values from col1 without duplicates, ...
    (microsoft.public.sqlserver.connect)
  • I need help with SELECT statement
    ... accomplish my final goal. ... In col1 rows have many duplicates ... col2 has unique values ... Return row values from col1 without duplicates, ...
    (microsoft.public.sqlserver.clustering)
  • I need help with SELECT statement
    ... accomplish my final goal. ... In col1 rows have many duplicates ... col2 has unique values ... Return row values from col1 without duplicates, ...
    (microsoft.public.sqlserver.ce)