Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

SQL SENTENCE

Hi I have a SQL Table:

VERSIONES_PLANOS
ID_PLANO varchar(20)
VERSION  smallint
ARCHIVO Image
THUMB  Image
DWF Image

And I have this data

id_plano : smt8
version:  0
archivo: <binary>
thumb: <binary>
dwf: <binary>

id_plano : smt8
version: 1
archivo: <binary>
thumb: <binary>
dwf: <binary>

I want to select * from versiones_planos where version = max(version)
but I dont know how to do the select sentence.

Thanks

0
olgavillamizar
Asked:
olgavillamizar
  • 4
  • 2
1 Solution
 
Anthony PerkinsCommented:
Select *
From VERSIONES_PLANOS
Where VERSION In (Select MAX(Version) From VERSIONES_PLANOS)
0
 
Anthony PerkinsCommented:
Or simpler:

Select TOP 1 WITH TIES *
From VERSIONES_PLANOS
Order By VERSION DESC
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
Hi olgavillamizar,


Or something like this


Select VERSIONES_PLANOS, ID_PLANO, ARCHIVO, THUMB, DWF, Max(version) Version
FROM urTable
Group by VERSIONES_PLANOS, ID_PLANO, ARCHIVO, THUMB, DWF

Aneesh R!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Atlanta_MikeCommented:
Actually best for performance would be

Select TOP 1 WITH TIES *
From VERSIONES_PLANOS
Order By VERSION DESC

submitted by ac
0
 
Anthony PerkinsCommented:
Perhaps, but only if that is what the questioner needs.  I get the distinct impression and reading between the lines that there is more to the question. We'll see or as the questioner may say "veremos"...
0
 
Atlanta_MikeCommented:
Oh... and justed noticed the with ties... It only works in 2005
0
 
Anthony PerkinsCommented:
>>It only works in 2005<<
I think you will find it is in SQL Server 2000, as well.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now