| Author |
Topic |
|
irene casper
Starting Member
4 Posts |
Posted - 2006-12-13 : 19:58:01
|
| table1:id, process, date(yyyymmdd)==================alice, aaa, 20061201alice, aaa, 20061203alice, aaa, 20061211brandon, bbb, 20061205brandon, bbb, 20061210casper, ccc, 20061213Is there any way to get the result of the following using a single query?id, process, date(yyyymmdd)==================alice, aaa, 20061211brandon, bbb, 20061210casper, ccc, 20061213 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-12-13 : 20:02:58
|
| SELECT id, process, MAX(date)FROM table1GROUP BY id, processTara Kizer |
 |
|
|
irene casper
Starting Member
4 Posts |
Posted - 2006-12-13 : 20:36:11
|
| let's hv a slight change of table1:id, process, date(yyyymmdd)==================alice, aaa, 20061201alice, aaa, 20061203alice, aaa, 20061211brandon, aaa, 20061201brandon, aaa, 20061212casper, aaa, 20061213alice, bbb, 20061211brandon, bbb, 20061213here, i 2 process: 'aaa' 'bbb'after i get the max(date) from each id in each process,i get:alice, aaa, 20061211brandon, aaa, 20061212casper, aaa, 20061213alice, bbb, 20061211brandon, bbb, 20061213and now i wanna find those id that exist in both process, which mean my result would be:alicebrandonhow can it be done? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-12-13 : 20:47:33
|
Try this:SELECT idFROM( SELECT id, process--, MAX(date) FROM table1 GROUP BY id, process) tGROUP BY idHAVING COUNT(*) > 1 Or this:SELECT idFROM( SELECT DISTINCT id, process FROM table1) tGROUP BY idHAVING COUNT(*) > 1 Tara Kizer |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-14 : 06:54:42
|
| orSELECT id, process FROM table1 GROUP BY id, processHaving count(*)>1MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|