I do have a question or maybe misconception about seraching in Mysql.
In my table I have 2 fields, first’s ID (int 8) and second’s used (int 1).
The used field just get 0 or 1 like boolean.
Assuming the number of rows’s 20001,
about ID: My last ID is 20001 and first ID’s 1.
about used: Just my first row which has ID = 1 is 1 and the others is 0.
Now when I wanna get one row, I write this code.It’s OK.
SELECT *
FROM `table`
WHERE `used` =0
LIMIT 0 , 1
I just want a row with 0 amount in used.
But my problem is : I imagine, Mysql search all of the 20000 rows, and so give me one row. This will hurt me because I just want one row with 0 amount in used
what’s the best way for doing?
Will give you all rows which used value is 0, with:
Will give you one row which used value is 0.
If this is not what you are looking for, can you clarify your question?
If you need the last record
Edit:
If you are worried about speed of your queries I suspect that if you start up your mysql via command line (or tool you prefer) and run queries provided to a table with only that much records you will get sentence saying how long it will take, it might say (0.00 sec) if its absolutely nothing. 🙂
If your table gets more complicated consider learning to use mysql indexes for certain columns: http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
About reserved words in MySQL:
Your table naming caught my attention and you should consider of using something other than
tableas table name so you don’t need to use quotation marks around table word when using it. (you are also using them around wordusedwhich is not even reserved word.List of reserved words which should be avoided to be used within MySQL(5.5): http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html