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 |
|
antgaudi
Starting Member
4 Posts |
Posted - 2009-04-19 : 19:30:21
|
I have this code:select distinct pil_pilotname, dep_dep_datefrom departures, pilotswhere dep_dep_date < sysdateand dep_pilot_id = pil_pilot_id;The result gives me:PIL_PILOTNAME DEP_DEP_D------------------------------ ---------Leiss, Ernst L. 19-APR-09Harris, Kenneth C. 18-APR-09Long, Stuart 18-APR-09Long, Stuart 19-APR-09Long, Stuart 08-APR-09Harris, Kenneth C. 08-APR-09Leiss, Ernst L. 08-APR-09Pasewark, William B. 10-APR-09Harris, Kenneth C. 02-APR-09PIL_PILOTNAME DEP_DEP_D------------------------------ ---------Pasewark, William B. 17-APR-09Pasewark, William B. 01-APR-09Harris, Kenneth C. 19-APR-09Pasewark, William B. 08-APR-09I'm trying to retrieve only the most recent departure date for each pilot. What am I missing Thanks. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-20 : 04:13:07
|
| Try this tooselect pilots.pil_pilotname, max(dep_dep_date) as dep_dep_datefrom departures inner join pilotson departures.dep_pilot_id = pilots.pil_pilot_idwhere departures.dep_dep_date < sysdategroup by pilots.pil_pilotname;MadhivananFailing to plan is Planning to fail |
 |
|
|
antgaudi
Starting Member
4 Posts |
Posted - 2009-04-20 : 12:56:26
|
| Yours works great.Do you happen to know the difference though, between your input and the one below:select pil_pilotname, max(dep_dep_date)from departures, pilotswhere dep_dep_date < sysdateand dep_pilot_id = pil_pilot_idgroup by pil_pilotname/I noticed that both give the same results but I don't know which query would be the best (most updated) to use. Does it matter?Thanks. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-21 : 02:08:22
|
quote: Originally posted by antgaudi Yours works great.Do you happen to know the difference though, between your input and the one below:select pil_pilotname, max(dep_dep_date)from departures, pilotswhere dep_dep_date < sysdateand dep_pilot_id = pil_pilot_idgroup by pil_pilotname/I noticed that both give the same results but I don't know which query would be the best (most updated) to use. Does it matter?Thanks.
I used ANSI join MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|