我需要MySQL SELECT查询的帮助

I need help to write a MySQL query that would do the following for me:

It would select the last row from a certain column. Let's say the table name is 'mysite_codes' and the column name is 'code', there are many rows in this column, but I want the query to take the last added one and get my back one result in PHP (LIMIT 1 thing).

Would anyone please help me with this?

MySQL tables have no inherent sorting. If you want "the last added one" then you'll need an AUTO_INCREMENTing column like id.

Then you can write.

SELECT `code` FROM `mysite_codes` ORDER BY `id` DESC LIMIT 1

to get just the row with the highest id value.

Try this:

select code
  from mysite_codes
 order by add_date desc
 limit 1

Assuming you have an auto-incremementing id column called something like "auto_id_column":

SELECT code FROM mysite_codes ORDER BY auto_id_column DESC LIMIT 0, 1;