0
I have a problem plese help me
11 ответов
+ 3
This might work if using MySQL:
SELECT Id, MAX(Version) AS Version, *
FROM MyData
GROUP BY Id;
+ 3
There are a few ways to do this. The best answer depends on whether you are using transactional SQL, embedded SQL, or a stored procedure. The specific syntax depends on which SQL engine you are using.
At least to show you that it can be done, here is an approach that would work in Oracle transactional SQL, assuming your table name is MyData:
SELECT * FROM MyData As A WHERE Version = (SELECT Max(Version) FROM MyData As B WHERE A.Id = B.Id);
+ 3
So
As I wanted all fields and I am using SQL SERVER.
Brian's answer was more suitable.
But If It was MYSQL David's answer would be better.
Thanks a million.
I appreciate you both guys
+ 1
Can you please update your question with given answer. Though join you can get data with compound key or composite key.
https://www.w3resource.com/sql/joins/using-a-where-cluase-to-join-two-tables-related-by-a-composite-primary-key-or-foriegn-key-pair.php
+ 1
Both are correct
Thanks guys🤗
0
How can i do a search with compound key
0
Hi
0
I have a table
0
And it has compund key
for example
Id version title description
These are my fields
0
My data are like these
Id. Version. Title Descrip
1001 1. News1. Detail1
1001. 2. N2 d2
1002. 1. N1. D1
1003. 1. N1. D1
1003. 2. N1. D1
1003. 3. N1. D1
0
I want the records that have the last version
The bigger one
Id and version are compound key