Does MySQL "SELECT LIMIT 1" with multiple records select the first record from above?

I searched and searched and can’t find the answer to this question, maybe I'm asking about it wrong.

I am querying an employee database.

I need to get the details based on the position identifier, however, there can be several records for this position identifier, since this organization has permanent employees and temporary employees who act against the same position.

So, in order to get the CURRENT owner of the position identifier, I need my query to get the SELECT FIRST record corresponding to the position line from TOP DOWN.

will it select the first matching record from above?

SELECT * WHERE `position_id`="00000000" LIMIT 1; 

Thanks in advance.

+8
mysql select limit
source share
3 answers

An ORDER BY is required to determine the order between the individual records in your table. If you do not use ORDER BY , you can not fix the order between records, and each time you execute the query, you can get a new order.

+8
source share

From the manual:

Using one argument, the value indicates the number of rows returned from the beginning of the result set.

So, with LIMIT 1 you get the first row from the result set. The fact that the result set depends on the engine used and what indexes you have. If you want to add the first row, you need to create another column to determine this.

+3
source share

It just gets randomly * . It is not possible to determine which one will be if you do not add an ORDER BY .

* Of course, not at random. It depends on how you store the records, and repeated queries will likely return the same result every time, at least until you change the table or its contents. I really want to say you cannot be sure.

+2
source share

All Articles