Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL SENTENCE

Posted on 2006-06-28
7
Medium Priority
?
620 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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

916 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