關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • MySQL 中的變數

    Posted on December 4th, 2007 Sam Tang No comments

    一般上使用 MySQL 都是儲存資料及需要時抽取所需的資料,其實 MySQL 還有很多其他功能,以下介紹使用 MySQL 的變數刪除一些舊資料:

    select @del_time:=`time` from `article` order by `time` desc limit 499, 1;
    delete from `article` where `time`

    以上第一行 SQL,會定義一個 del_time 變數,value 是資料表 article 倒序排第 500 筆的 `time` 欄位。
    第二句是刪除在 article 資料表內時間比 del_time 還要舊的文章。


    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word