I have a problem plese help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I have a problem plese help me

2nd Apr 2020, 2:25 PM
Hamed Niazmand
Hamed Niazmand - avatar
11 Answers
+ 3
This might work if using MySQL: SELECT Id, MAX(Version) AS Version, * FROM MyData GROUP BY Id;
2nd Apr 2020, 5:54 PM
David Carroll
David Carroll - avatar
+ 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);
2nd Apr 2020, 4:22 PM
Brian
Brian - avatar
+ 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
2nd Apr 2020, 6:55 PM
Hamed Niazmand
Hamed Niazmand - avatar
+ 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
2nd Apr 2020, 2:37 PM
A͢J
A͢J - avatar
+ 1
Both are correct Thanks guys🤗
2nd Apr 2020, 6:09 PM
Hamed Niazmand
Hamed Niazmand - avatar
0
How can i do a search with compound key
2nd Apr 2020, 2:26 PM
Hamed Niazmand
Hamed Niazmand - avatar
0
Hi
2nd Apr 2020, 2:51 PM
Hamed Niazmand
Hamed Niazmand - avatar
0
I have a table
2nd Apr 2020, 2:52 PM
Hamed Niazmand
Hamed Niazmand - avatar
0
And it has compund key for example Id version title description These are my fields
2nd Apr 2020, 2:54 PM
Hamed Niazmand
Hamed Niazmand - avatar
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
2nd Apr 2020, 2:57 PM
Hamed Niazmand
Hamed Niazmand - avatar
0
I want the records that have the last version The bigger one Id and version are compound key
2nd Apr 2020, 2:58 PM
Hamed Niazmand
Hamed Niazmand - avatar