I've searched and searched and can't find an answer to this question, I'm probably asking it in the wrong way.
I am querying an employee database.
I need to get details based on a position id, however there could be multiple records for that position id as this organisation has permanent employees and temporary employees that act against the same position.
So, in order to get the CURRENT occupant of the position id, I need my query to SELECT the FIRST record that matches the position string, from the the TOP DOWN.
will this select the first matched record from the top?
SELECT * WHERE `position_id`="00000000" LIMIT 1;
Thanks in advance.
You need an
ORDER BY
clause to define the ordering between the individual records your table. If you do not useORDER BY
you can assume no fixed order between the records, and you could get a new order each time you executed the query.From the manual:
So with
LIMIT 1
you get the first row from the result set. What the result set is depends on engine used and which indexes you have. If you want the first row added, you need to create another column to define that.It just gets one at random*. There's no way to tell which one it will be, unless you add an
ORDER BY
clause.* Not really at random, of course. It depends on the way the records are stored and repeated queries will probably return the same result every time, at least as long as you don't modify the table or its contents. I actually mean, you cannot be sure.