View previous topic :: View next topic
|
Author |
Message |
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Following is the Table
Table1 Having Columns A and B
Code: |
Column1 Column2
------- --------
A 1
B 2
C 1
D 1
E 2
S 3
A 2
|
Following is the Query
Code: |
Select Max(Column1) From Table1
Where Column2 = 1; |
But i want the value as below
i.e maximum value per unique item in coulmn1 for the Value 1 in Column2
Please suggest how to modify the SQl query to get the result.
Thanks,
Sree |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Code: |
Select distinct Column1 From Table1
Where Column2 = 1;
|
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
to obtain the expected results:
Quote: |
But i want the value as below
|
from the table contents as provided by the TS
Quote: |
Table1 Having Columns A and B
Code: |
Column1 Column2
------- --------
A 1
B 2
C 1
D 1
E 2
S 3
A 2 |
|
the sql would have to be: (with or without the DISTINCT)
Code: |
SELECT COLUMN1 <<< or is it COLUMNA ?
FROM TABLE1
WHERE COLUMN2 = 1 <<< or is it COLUMNB ?
OR COLUMN1 = 'E' <<< or is it COLUMNA ?
|
IF the sreekusr wants something different,
he will have to provide alternative column values
or alternative results as well as consistant column names. |
|
Back to top |
|
|
|