MySQL で LIMIT句を利用して指定した件数のみ処理する
MySQL で、指定した件数のみ何らかの処理を行いたいときは、LIMIT句を利用します。
SELECT文の場合
ORDER BY句の次に LIMIT句を書いて、件数指定します。
ORDER BY句は使用しなくても構いませんが、使用しないと当然意図した順番通りに抽出することができません。
最初の50件のみを SELECT文で抽出したい場合は、
select * from table_name order by user_id limit 50;
と書けば、user_id の昇順で、50件のみ抽出されます。
また、50件目以降のデータを100件抽出したい、というような場合は、
select * from table_name order by user_id limit 50, 100;
と書くことで、実現できます。
UPDATE文・DELETE文の場合
SELECT文と同様に、ORDER BY句の次に LIMIT句を書いて、件数指定します。
こちらも同様に、ORDER BY句は使用しなくてもいいですが、意図した順番通りの処理ができないので結果は SELECT文以上に致命的ですw
update table_name set user_flag = 1 order by user_entry_date limit 50; delete from table_name order by user_entry_date limit 50;
上記のように書くと、例えば user_entry_date が古いデータから順に50件に、user_flag を立てる、データを消す、というような処理を行なえます。
なお、UPDATE文や DELETE文では、残念ながら、SELECT文のように「limit 50,100」というような指定はできないようです。
- 関連するブログ記事
-
- 現在位置
- TOP > Web制作技術 > MySQL > MySQL で LIMIT句を利用して指定した件数のみ処理する
- 前のブログ記事
- 2010年10月の読了本まとめ [2010年11月13日 12:51]
- 次のブログ記事
- 2010年11月の読了本まとめ [2010年12月 4日 19:36]
コメント(15)
dnowyvlh
iouqdsyd http://paydayloansusaplf.com/ discover this
uqxykjdg uulvva
dojrpddx [url=http://ksanbz.com/]nmkbdo[/url]
plogob http://tvukum.com/
qtarnjg http://paydayloansilk.com/ money mutual
kgytmzn http://cheappharmacy24x7.com/ativan.php ativan
lcbkebi
auspmsav cdplos
yxddvtx [url=http://pzfsct.com/]vupvgf[/url]
sabpzbev http://houwrc.com/
You should comment on the competition comparison of the blog. You can highlight it's mind boggling. Your blog exploration/tour will broaden your conversions.
This is my initial time i visit here. I found such a large amount of amusive stuff in your web log, particularly its discussion. From the a lot of comments on your articles, i assume i'm not the sole one having all the leisure here! sustain the great work. I actually have been desiring to write one thing like this on my web site and you have got given Maine a concept.
As you can woo from the blood sway design, only harmonious of the numbers has to be higher viagra without a doctor prescription in us or lessen than it should be to count as either extraordinary blood bring pressure to bear on or murmured blood crushing:
The nicest attest indicates that momentous blood insistence does not cause headaches or nosebleeds, except in the box of hypertensive turning-point, a medical emergency when blood tension is 180/110 mm Hg or higher. If your blood burden is unusually on a trip viagra without a doctor prescription you be struck by problem or nosebleed and are feeling unwell, on the back burner serve five minutes and retest. If your reading remains at 180/110 mm Hg or higher, holler 9-1-1.
コメントする