Solved

SQL SENTENCE

Posted on 2006-06-28
7
612 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

729 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