Select only the first line of each user

Asked

Viewed 110 times

-1

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

It would be something like that:

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

I’ve tried with top 1, and limit 0,01 but it was a mistake.

  • What is the database server? Mysql, Oracle, ...

  • 2

    To recover the data from the first deposit take the record with the oldest date. Do not rely on the order in which the DBMS retrieves the records because, depending on the DBMS, it will not necessarily be in the same order in which they were recorded.

  • It would mysql the database

1 answer

1


Good afternoon.

The query you put up 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 a user id. However, assuming it is a user id, 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 results obtained by the first part of the query). If you want, you can add a sort parameter, using an "Order By ASC" (ascending order) or "Order By DESC" (descending order).

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.