Re: I need help with SELECT statement



It's not completely crystal clear what you need, but my guess is:

SELECT t1.col1, t1.col2
FROM table1 t1
INNER JOIN (SELECT col1, MAX(col3) AS col3
FROM table1
WHERE col3 <= @v
GROUP BY col1) t2
ON t1.col1 = t2.col1 AND t1.col3 = t2.col3

--
Jacco Schalkwijk
SQL Server MVP


"Vanessa Lee" <van77788@xxxxxxxxx> wrote in message
news:Q7ydnWLCvMGoi8LfRVn-iQ@xxxxxxxxxxxxxx
> 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

  • Use distinct on one column but want 2 columns of data returned
    ... Col1, Col2 I want my result to have both columns of data based ... TableB: Col3 ... The result I get has duplicates. ... I have also tried this query: ...
    (microsoft.public.sqlserver.mseq)
  • Re: Use distinct on one column but want 2 columns of data returned
    ... Col1, Col2 I want my result to have both columns of data ... TableB: Col3 ... The result I get has duplicates. ... I have also tried this query: ...
    (microsoft.public.sqlserver.mseq)
  • RE: I need help with SELECT statement
    ... col1 you want to take in case qualifying rows have duplicate in col1. ... "Vanessa Lee" wrote: ... > Return row values from col1 without duplicates, ...
    (microsoft.public.sqlserver.datawarehouse)
  • Re: Cant create Primary Key???
    ... Col1 ... >>This will reveal the duplicates. ... >>Thomas A. Moreau, BSc, PhD, MCSE, MCDBA ... >>Columnist, SQL Server Professional ...
    (microsoft.public.sqlserver.server)
  • Re: I need help with SELECT statement
    ... Learn how not to multi-post to every single group and next time maybe you'll ... SQL Server MVP ... > In col1 rows have many duplicates ... > Return row values from col1 without duplicates, ...
    (microsoft.public.sqlserver.tools)