Reputation: 77
borrow_id borrower_id book_id borrow_date expected_return_date
1 19 6 0000-00-00 0000-00-00
2 1 10 0000-00-00 0000-00-00
3 20 1 0000-00-00 0000-00-00
4 18 3 2016-04-30 2016-05-02
5 19 8 2016-04-30 2016-05-03
6 21 7 2016-04-30 2016-05-03
7 22 14 2016-01-05 0000-00-00
8 13 1 2016-05-02 2016-06-04
9 18 3 2016-06-02 2016-05-26
12 23 14 2016-06-02 2016-05-03
13 1 5 2016-05-02 0000-00-00
14 23 1 2016-05-02 2016-05-03
This is my table. For same values of borrower_id column I want one borrow_id which is bigger of all. for example there are borrower_id 19 two times.I want borrow_id 5 row not borrow_id 1 row as 5>1.
What will be the query for that?
Upvotes: 0
Views: 44
Reputation: 4562
select * from borrow where borrow_id =
(select max(borrow_id) from borrow where borrower_id=19)
Upvotes: 0
Reputation: 133360
You can use a where in with a subselect grop by
select * from my_table
where (borrow_id, borrower_id) in (select max(borrow_id), borrower_id
from my_table group by borrower_id);
Upvotes: 3