Ruttensoft
asked on
SQL Question
Hello
I have some table like this:
A B
1 1
1 3
1 2
2 2
2 1
2 3
Now I want only these rows, where b is the highest value for A
So i want:
1 3
2 3
But it's not always 3 the highest value
How can I do that?
Thanks
I have some table like this:
A B
1 1
1 3
1 2
2 2
2 1
2 3
Now I want only these rows, where b is the highest value for A
So i want:
1 3
2 3
But it's not always 3 the highest value
How can I do that?
Thanks
try this.
SELECT A,MAX(B) AS B
FROM YourTable
GROUP BY A
ASKER
Hm, so mytable is tbl_back_checkliste_aktiv, a = tbl_back_checkliste_aktiv_ checkliste _typid, b = tbl_back_checkliste_aktiv_ checkliste _version gives me this, right:
select t.*
from tbl_back_checkliste_aktiv t
where t.tbl_back_checkliste_akti v_checklis te_version = (select max(i.tbl_back_checkliste_ aktiv_chec kliste_ver sion) from tbl_back_checkliste_aktiv i where i.tbl_back_checkliste_akti v_checklis te_typid= t.tbl_back_checkliste_akti v_checklis te_typid)
But the query says:
There was an error parsing the query. [ Token line number = 3,Token line offset = 59,Token in error = select ]
What have I done wrong?
select t.*
from tbl_back_checkliste_aktiv t
where t.tbl_back_checkliste_akti
But the query says:
There was an error parsing the query. [ Token line number = 3,Token line offset = 59,Token in error = select ]
What have I done wrong?
ASKER
Thanks Sarath, that did it!
ASKER
Ups, another thing: I have other columns in the table, so column d, e and f.
How can I add them to this query?
How can I add them to this query?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Boooooaa nice, thanks!!
I also updated your original query :)
SELECT T1.*
FROM tbl_back_checkliste_aktiv T1
INNER JOIN (SELECT tbl_back_checkliste_aktiv_checkliste_typid,
MAX(tbl_back_checkliste_aktiv_checkliste_version) AS tbl_back_checkliste_aktiv_checkliste_version
FROM tbl_back_checkliste_aktiv
GROUP BY tbl_back_checkliste_aktiv_checkliste_typid) AS T2
ON T1.tbl_back_checkliste_aktiv_checkliste_typid = T2.tbl_back_checkliste_aktiv_checkliste_typid
AND T1.tbl_back_checkliste_aktiv_checkliste_version = T2.tbl_back_checkliste_aktiv_checkliste_version
ASKER
Thanks a lot!
you are welcome
Open in new window