Solved

SQL SENTENCE

Posted on 2006-06-28
7
606 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to extract a number from a MS SQL server string. 39 64
Extract XML Data from using TSQL 5 32
Report Builder 9 31
Sql query 34 22
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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 to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now