Select only the first row of each user

-1

I have a table where I move balance (deposits and withdrawal), but in a field of the site I need to bring only the balance of the first deposit.

It would look something like this:

select saldo from historico where id = :id and (algum filtro)

I have tried with top 1 , and limit 0,01 but gave error.

    
asked by anonymous 29.12.2018 / 19:16

1 answer

1

Good afternoon.

The query you put in is a bit confusing because it is not noticeable if the "id" column refers to the unique identifier of a record in that table or if it is the id of a user. However, assuming it is the id of a user, then you can use the following query:

Select saldo From historico Where id = :id Limit 1

This returns a single record of the table (the first of the result obtained by the first part of the query). If you want, you can add a sort parameter using an "Order By ASC" or "Order By DESC."

I hope I have helped.

    
29.12.2018 / 19:34