Reputation: 1645
I has 1 Table data ex:
A B C D
100 1 1 1
100 2 1 0
Key: Columns A and B
My Sql:
select *,max(B) from Table where D=1 group by A
Result : Row 1
I only want select Row 2. If Row 2 has D=0 ,Result is null.
or this data: i want get row 4 and row 5 has: max(B) and D=1
A B C D
100 1 1 1
100 2 1 0
101 1 1 1
101 2 1 1
102 1 1 1
How only select max row in sqlite? Thanks all.
Upvotes: 0
Views: 128
Reputation: 3118
I think that this query can help you:
select t1.* from table1 t1,
(select max(B) MB,max(A) MA from table1)t2
where (t1.A = t2.MA or t1.B = t2.MB) and
t1.D = 1;
Upvotes: 0
Reputation: 18600
Try this
SELECT *
FROM TABLE
WHERE (B,A) IN
(SELECT max(B),A
FROM TABLE
GROUP BY A
)
AND D=1;
Upvotes: 2