Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SQL - SELECT all versions but the highest one

Tags:

sql

I'm having trouble selecting all versions, just not the last version in my database using SQL.

This is what my database looks like:

id | titleid | version
----------------------
1  | TEST1   | 1.27
2  | TEST1   | 1.28
3  | TEST1   | 1.29
4  | TEST1   | 1.30
5  | TEST2   | 1.05
6  | TEST2   | 1.06
7  | TEST2   | 1.07
8  | TEST2   | 1.08

I want to SELECT the records 1, 2, 3, 5, 6, 7 since they're not the highest version.

I've tried searching SO but I can't seem to find anyone having the same issue as me.

Does anyone know how I can do this? Appreciate it a lot.

like image 701
Appel Flap Avatar asked Nov 20 '25 11:11

Appel Flap


1 Answers

Is this what you want?

select t.*
from t
where t.version < (select max(t2.version) from t t2 where t2.titleid = t.titleid);
like image 129
Gordon Linoff Avatar answered Nov 23 '25 00:11

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!