Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Mazdak
Yak Posting Veteran
63 Posts |
Posted - 2002-12-02 : 15:27:09
|
| I have an table like this:Date | Priority | PrimaryKey====== ========= ======12/2/2002 101 112/3/2002 101 212/4/2002 101 312/5/2002 101 412/6/2002 111 512/11/2002 111 612/12/2002 111 712/13/2002 111 812/4/2002 121 9 12/14/2002 121 1012/15/2002 121 1212/16/2002 121 13I want to make query command to get ONLY PRIMARYKEY of minimum date for each group of prirority:12/2/2002 101 112/6/2002 111 512/4/2002 121 9If I use this command:select min(Date),PrimaaryKey from table3 where (Date<GetDate() ) group by PriorityI'll get two column but I have to only get PrimaryKey column because I want to use in WHERE of UPDATE commandIEdited by - mazdak on 12/02/2002 15:32:34 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-12-02 : 15:51:38
|
Use your select statement as a derived table and in the outer select only choose the columns you want ...select a.afrom (select a, b from abtable) as a Jay White{0} |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-12-02 : 16:09:36
|
| I think this may be what you are asking for, and what Jay was implying you should try:SELECT Priority, PrimaryKeyFROMTable3INNER JOIN(SELECT Priority, Min(Date) as MinDate FROM Table3 GROUP BY Priority) AON A.Priorty = Table3.Priority AND A.MinDate = Table3.MinDate- Jeff |
 |
|
|
Mazdak
Yak Posting Veteran
63 Posts |
Posted - 2002-12-03 : 02:18:41
|
Thanks to both of you.Thats what I want. |
 |
|
|
|
|
|