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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-01-05 : 08:14:02
|
| mo writes "hi all,got an easy oen here...i got 2 tables in sql srvr2000. one contains galleries and the other projections.i want to return all galleries that match a nile like '%gomez%' but only if the gallery_id is not 'trashed' in the projected table.here is the curver ball. the projected table can have no records or multiple records for any given gallery. if it has no record that is fine but if it has many i need to find the most recent and make sure its gallery_type is not "trashed". if there are multiple records for a gallery then the most curent is the one i need to check for if it is trashed. there is a date field for this.the tables are linked by galelry_idthank you all." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-01-05 : 08:36:04
|
| from galleries gleft join (select gallery_id , dte = max(dte) from projected group by gallery_id) pmaxon g.gallery_id = pmax.gallery_id left join projected pon p.gallery_id = pmax.gallery_id and p.dte = pmax.dtewhere g.nile like '%gomez%' and (p.trashed = 1 or p.trashed is null)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|