• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

How to get the last record ?

HI

I have a table that contains payments related to an order (IdOrder, IdPayment, Amount, Date), in that table can be zero, one or more payments with different IdPayment and I need to create an sql query that returns the last IdPayment.

Regards.
0
dimensionav
Asked:
dimensionav
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
select max(IdPayment) PayMent from <table>
where orderId = 2134
0
 
dimensionavAuthor Commented:
PayMent works like an alias?
0
 
maziqbalCommented:
If you want to get last idPayment(Means that was entered first) for an order you can do like this:(Using mysql sql query)

select IdPayment from <table> where orderId = 123 order by date limit 1
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now