Solved

SQL SENTENCE

Posted on 2006-06-28
7
608 Views
Last Modified: 2006-11-18
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
Comment
Question by:olgavillamizar
  • 4
  • 2
7 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 17003085
Select *
From VERSIONES_PLANOS
Where VERSION In (Select MAX(Version) From VERSIONES_PLANOS)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17003096
Or simpler:

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

Expert Comment

by:Aneesh Retnakaran
ID: 17003117
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 17003241
Actually best for performance would be

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

submitted by ac
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17003263
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
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 17003504
Oh... and justed noticed the with ties... It only works in 2005
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17003608
>>It only works in 2005<<
I think you will find it is in SQL Server 2000, as well.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question